From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6F6AA42B4B; Fri, 19 May 2023 18:46:17 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EC08C40E25; Fri, 19 May 2023 18:46:16 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id 3496B40E09; Fri, 19 May 2023 18:46:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684514775; x=1716050775; h=message-id:date:subject:to:cc:references:from: in-reply-to:content-transfer-encoding:mime-version; bh=B+X6/P0egIyGNuVYIZ2aI8DwgEH42Y+j/FVboYgGKuc=; b=JYxvsux5xxw5OatQq5K8DDMR2mUsBA3XbkRuHiHf/WaYno+OD7B9U5aA IQfNgP2uXPYbpGCQxAihhkJIwDUTQiBhYfZBxvGnkMrlMw72QtNClgLKS T5Q2X372hJoYwVMFwyuSF7pJZwQ3ye9F9YG1S6GBUHxpreDPW5L4JhneK 5gcHiHke8Kf1/CLTX47Q+StbQ9FU0prvNkHf+LI/QdJ8S3OrhgiwC+j8x Me+I0BtXIw8i7QbMZA0VZraCSEYTxB6z+J/CcylmGb5zl/KkMaBI9nGFY V27TpD1Ma+fAnTsHTz9wD+noyNl3o4HU7V1mWHkws4tV443DbgAOeSRFZ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10715"; a="418117958" X-IronPort-AV: E=Sophos;i="6.00,177,1681196400"; d="scan'208";a="418117958" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 May 2023 09:46:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10715"; a="696771589" X-IronPort-AV: E=Sophos;i="6.00,177,1681196400"; d="scan'208";a="696771589" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga007.jf.intel.com with ESMTP; 19 May 2023 09:46:05 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Fri, 19 May 2023 09:46:05 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Fri, 19 May 2023 09:46:05 -0700 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.177) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.23; Fri, 19 May 2023 09:46:04 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mxqRlq7dlItbtpfCtm1PnxPx7fLXlBppzvzUNqSZq9Gy9aa9TlGmMpT8tc74kAlS9ZqaGMZwDwnPK6E7eYhs9ahV6WxSKiv9nGGu9GgFCQGPJu26yy79RnDy8n+QeIYvR6s54Pdq6NnW4Lis9MEapFeC9nC0qGA1dcPHsh8TI53jgoQa93L2zZlI+9FkopJQUeginBeii3qEGyKfgPCw53H4HPAjjvXxyexVlva5TRccONiXW5CikS/rqINGMuBdtIZ4+3DGd4aIVbIDrltZ88V5RqyycGs7bNW2FqIMkHv/htQGc5KNGHCrk91fGLFYwtTolgrXeA5ZeX5HKgSkyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=I3a4rzOSrU6slHK7whA4wGz3C8UXwyuviDCyEvoGwHg=; b=PgO8Y8LM26suO0+lQ4+8xkt9FDm2Q9bbcW+vsBqBSOCAFZLlLKssqlPIWKIRXf/BIoRlN5apbSRS0CGRnCiPO9iu9V6Du/RETcLGoGd5gzpP4JgCs6WWphqUeDT3BsFoELxFXpLxLaElo4Ke0KSa8YvDk03hMuSd2rqMU0ovjqs9z0Ciec6IsPGQ8PjwyDWVhG5dGNH7ytobsz1LnOyIkiN83u1OPNEwRANlYdX0AenSC5bX/wia7JX1+OK0ruH/WRk+IQVbe/6uujLx1Dptn/8smp4JxLZeHNlnsPKa4zeJaQCevAmDLlDcDKBLC8C+6zlmKEpiZzj/YXZOBr8AUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB6502.namprd11.prod.outlook.com (2603:10b6:8:89::7) by SJ2PR11MB7428.namprd11.prod.outlook.com (2603:10b6:a03:4cf::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.17; Fri, 19 May 2023 16:46:02 +0000 Received: from DM4PR11MB6502.namprd11.prod.outlook.com ([fe80::49c0:aa4c:e5b4:e718]) by DM4PR11MB6502.namprd11.prod.outlook.com ([fe80::49c0:aa4c:e5b4:e718%5]) with mapi id 15.20.6411.021; Fri, 19 May 2023 16:46:02 +0000 Message-ID: Date: Fri, 19 May 2023 17:45:56 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.11.0 Subject: Re: [PATCH 2/2] Memory Allocation: Alternative fix for ignore_msk during find_next_n() in fb_array library Content-Language: en-US To: Vipin P R CC: , References: <1673615669-21011-1-git-send-email-vipinp@vmware.com> <1673615669-21011-3-git-send-email-vipinp@vmware.com> From: "Burakov, Anatoly" In-Reply-To: <1673615669-21011-3-git-send-email-vipinp@vmware.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO2P265CA0370.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a3::22) To DM4PR11MB6502.namprd11.prod.outlook.com (2603:10b6:8:89::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB6502:EE_|SJ2PR11MB7428:EE_ X-MS-Office365-Filtering-Correlation-Id: 2cd26c34-3257-40d0-ab27-08db588887ce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rhmyXeW14CDKd4vgCzOYdrFApmNcD43JklI3wBKiTGokX95TNBfuBOXnryPkesGjYOdO+g0Wu1VMRHBR+F3OtodJZ8V3X5lqMykP5T6nD3fl9XPtkZwyA/Jpvn4BlPm6o0W5lCxBA5NS2YRxSUai7cGzTI1MUgpsmgA3qxACmRUGX4RVpoeEKJl7kfJyVRRTZUySrckcuj1ZeuBdVVxKB+w1JlnFSS/fDGl9hKQG7A4pV6MuqzRVqM9SdoV+GFguQgBMTkT4bnsgWWxuNCn1BgZlFae8tZHNPRRfuJ4r81znJW97LdvvQq9P8cMiDREqYzyLlIE5Z/Mww5lU5scn+KM84ERgvdZnSj5OMYxyHLbd4AVxzxpOCpoeewhdKZ4vP2ZAshFudzANVeqqn+yGAPCb3++zyv33rPIpADpyCz8btMyXPQmmRJ3rbYp78w/vR9jYLDRktSMNkvzXPJult6lPXwK5QQM52yaiw7sgLMGpAJ3s41KgYpsxKeHPX9jFm3735jNPWLWeq6HfeO2nj++6KaqGBrdn33KEUCRDMD5kZ1x+UyrJA606HK+kPXCKCRKSXqxSDCt9POzNoJ8XDxc35nQqWS9ocll7bgn8FYgcQ0peCy7BAi5Vtcx98J6VNA/TT5dQog5M69HiS9wOXA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB6502.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(396003)(39860400002)(376002)(366004)(346002)(136003)(451199021)(478600001)(8936002)(6666004)(316002)(66556008)(66946007)(6486002)(41300700001)(66476007)(6916009)(8676002)(2616005)(6506007)(6512007)(53546011)(2906002)(186003)(83380400001)(31686004)(4326008)(26005)(82960400001)(38100700002)(86362001)(31696002)(5660300002)(36756003)(43740500002)(45980500001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?RHlXakZCMVd3NlY5anphYXIrdjJRSm9mZjZublRudGduSHhPcmlMUlBjSysy?= =?utf-8?B?LzJDNXY0cFlkUDRQMlRzSU5zTDV0aTRKM2dBckhKMHVnZWE3b1RvTmJMS0Vl?= =?utf-8?B?L1ZtS1djNjNJL1FvK3pVWm43RnBOU25HaEVQVDhuMVRSanFPK29NNUo1cEpq?= =?utf-8?B?M1NqL3VyWXVTZVdOWjU0V0dZZmNGVXFMQzdYN0lNQUMxd0NMNXJyM0ZWL2h5?= =?utf-8?B?NENZREJ2SFp3RTZSajNWN2xiNHpFU1VoUWZ4eXdpTW95OE9pdmVyc0w3QmR3?= =?utf-8?B?cDZhU01WeDZHbU1QczZZS0p4ZlZPUEo3bEtVdDhXaVhVSmZyc09mY0NBM05U?= =?utf-8?B?MTJKZTF2RVNtRjlaZzZldnVvV0VqSnhmckE3bGRrL0tqemlyRGlLU3lIVmVv?= =?utf-8?B?NDkzeUVZU1hVS0wyM2V2TlRzRFdBTVlnOGNPL0RNNkhFQStsbXFqbUpKYUdr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-AuthSource: DM4PR11MB6502.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2023 16:46:02.1963 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rcVNUMWKmmsUJNKvrU7hQuN5SOFJuiRZi0uiqmEUZ51tNeiM+YnEh4R/veqlSTFio12ZXH555uRSFgrMkIV/G+2hvPfPJv3zelTzGay7CyI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR11MB7428 X-OriginatorOrg: intel.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Hi, This is technically not a bug fix but an improvement to the lookahead algorithm, so I don't think this needs a Fixes: tag or a Cc to stable. On 1/13/2023 1:14 PM, Vipin P R wrote: > Ignore mask ignores essential bits WHICH could have been contiguous. > This commit aims to rectify that > Suggested rewording: fbarray: improve lookahead ignore mask handling Currently, when lookahead mask does not have its first bit set but has other bits set, we do not set any ignore masks to avoid potentially ignoring useful bits. We can still ignore some bits, because we can rely on the fact that we're looking for `need` bits, and lookahead mask does give us information about whether there are other potential places we can start looking for runs in the next iteration. Address this by ignoring least significant clear bits in our lookahead mask on next iteration. > Cc: stable@dpdk.org > > Signed-off-by: Vipin P R > Acked-by: Kumara Parameshwaran > --- > Depends-on: 0001-Memory-Allocation-Fixes-ms_idx-jump-lookahead-during.patch > Depends-on: 0002-Memory-Allocation-Fixes-ms_idx-jump-lookbehind-durin.patch > --- > lib/eal/common/eal_common_fbarray.c | 21 ++++++++++++++++++--- > 1 file changed, 18 insertions(+), 3 deletions(-) > > diff --git a/lib/eal/common/eal_common_fbarray.c b/lib/eal/common/eal_common_fbarray.c > index 313681a..29fffb6 100644 > --- a/lib/eal/common/eal_common_fbarray.c > +++ b/lib/eal/common/eal_common_fbarray.c > @@ -138,7 +138,7 @@ find_next_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n, > last_msk = ~(UINT64_MAX << last_mod); > > for (msk_idx = first; msk_idx < msk->n_masks; msk_idx++) { > - uint64_t cur_msk, lookahead_msk; > + uint64_t cur_msk, lookahead_msk, lookahead_msk_; `lookahead_msk_` doesn't need to be in the outer loop, IMO it can be moved inside the lookahead code. Also, `lookahead_msk_` is not a very informative name. Maybe change it to `lookahead_old` or similar? > unsigned int run_start, clz, left; > bool found = false; > /* > @@ -215,12 +215,14 @@ find_next_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n, > > for (lookahead_idx = msk_idx + 1; lookahead_idx < msk->n_masks; > lookahead_idx++) { > - unsigned int s_idx, need; > + unsigned int s_idx, need, fsb_idx, fcb_idx, ignore_bits; > lookahead_msk = msk->data[lookahead_idx]; > > /* if we're looking for free space, invert the mask */ > if (!used) > lookahead_msk = ~lookahead_msk; > + > + lookahead_msk_ = lookahead_msk; > > /* figure out how many consecutive bits we need here */ > need = RTE_MIN(left, MASK_ALIGN); > @@ -236,10 +238,23 @@ find_next_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n, > * as well, so skip that on next iteration. > */ > if (!lookahead_msk) { > - /* There aren't "need" number of contiguous bits anywhere in the mask. > + /* There aren't "need" number of contiguous bits anywhere in the mask. > * Ignore these many number of bits from LSB for the next iteration. > */ > ignore_msk = ~((1ULL << need) - 1); > + } else { > + /* Find the first clear bit */ > + fcb_idx = __builtin_ffsll((~lookahead_msk_)); > + /* clear all bits upto the first clear bit in lookahead_msk_. */ > + lookahead_msk_ = lookahead_msk_ & ((~0ULL) << fcb_idx); > + /* find the first set bit in the modified mask */ > + fsb_idx = __builtin_ffsll(lookahead_msk_); > + /* number of bits to ignore from the next iteration */ > + ignore_bits = fsb_idx - 1; > + /* ignore all bits preceding the first set bit after the first clear bit > + * starting from LSB of lookahead_msk_. > + */ > + ignore_msk = ~((1ULL << ignore_bits) - 1); > } I don't quite understand what's happening here. Or rather, I kind of do, but I don't understand why we don't just 1) find first set bit in lookahead mask, and 2) ignore all preceding bits? E.g. something like: /* find first set bit */ fsb_idx = __builtin_ffsll(lookahead_msk); /* ignore all preceding bits */ ignore_msk = ~((1ULL << fsb_idx) - 1); would be much simpler and achieve the same result, would it not? > msk_idx = lookahead_idx - 1; > break; -- Thanks, Anatoly