Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43BE71FAA for ; Mon, 15 Jan 2024 04:25:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Hb/ZeiT5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705292728; x=1736828728; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=jQBlAV4p5/ywuHqFD+3l8FNasA0j7GohoEA/vJyB/q4=; b=Hb/ZeiT5Fy7APMdvTakzTiAmH4Wg7nvpgPJiUBB1Fg1gsSpXwILd3xhx CnjDXA4TTb2Y9iCJ+4XnMUhg8iji3xRPtlh+cX1IDvoK4AvN4ymEgLZ6i cbdsIoF5DC23wp7ikT47mA2v3mcnResvdvR9kuHLrSwTF5IdvXX9pDy8L y6i6xU2zuoqKxn2qjYSwlnvKNpSmv39wnEIxkMBQHkcqAAp6iwSKoERJx DJi+nX66jRq588Q+fOvw28w/zIquI1buqEUTZ5DiAB8FTeMFP3Ws6OjPU Fw1l7W0SUVQFTCy2sLPnRsPLDoCjbs4KFDDrg4KERZ/p/4eIBICNROlul A==; X-IronPort-AV: E=McAfee;i="6600,9927,10953"; a="389978588" X-IronPort-AV: E=Sophos;i="6.04,195,1695711600"; d="scan'208";a="389978588" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jan 2024 20:25:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10953"; a="906945453" X-IronPort-AV: E=Sophos;i="6.04,195,1695711600"; d="scan'208";a="906945453" Received: from xiaoyaol-hp-g830.ccr.corp.intel.com (HELO [10.93.22.149]) ([10.93.22.149]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jan 2024 20:25:23 -0800 Message-ID: <5a004819-b9bf-4a2e-b8b3-ed238a66245a@intel.com> Date: Mon, 15 Jan 2024 12:25:19 +0800 Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v7 14/16] i386: Use CPUCacheInfo.share_level to encode CPUID[4] Content-Language: en-US To: Zhao Liu Cc: Eduardo Habkost , Marcel Apfelbaum , "Michael S . Tsirkin" , Richard Henderson , Paolo Bonzini , Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org, Zhenyu Wang , Zhuocheng Ding , Zhao Liu , Babu Moger , Yongwei Ma References: <20240108082727.420817-1-zhao1.liu@linux.intel.com> <20240108082727.420817-15-zhao1.liu@linux.intel.com> From: Xiaoyao Li In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/15/2024 11:40 AM, Zhao Liu wrote: >>> +{ >>> + uint32_t num_ids = 0; >>> + >>> + switch (share_level) { >>> + case CPU_TOPO_LEVEL_CORE: >>> + num_ids = 1 << apicid_core_offset(topo_info); >>> + break; >>> + case CPU_TOPO_LEVEL_DIE: >>> + num_ids = 1 << apicid_die_offset(topo_info); >>> + break; >>> + case CPU_TOPO_LEVEL_PACKAGE: >>> + num_ids = 1 << apicid_pkg_offset(topo_info); >>> + break; >>> + default: >>> + /* >>> + * Currently there is no use case for SMT and MODULE, so use >>> + * assert directly to facilitate debugging. >>> + */ >>> + g_assert_not_reached(); >>> + } >>> + >>> + return num_ids - 1; >> suggest to just return num_ids, and let the caller to do the -1 work. > Emm, SDM calls the whole "num_ids - 1" (CPUID.0x4.EAX[bits 14-25]) as > "maximum number of addressable IDs for logical processors sharing this > cache"... > > So if this helper just names "num_ids" as max_lp_ids_share_the_cache, > I'm not sure there would be ambiguity here? I don't think it will. if this function is going to used anywhere else, people will need to keep in mind to do +1 stuff to get the actual number. leaving the -1 trick to where CPUID value gets encoded. let's make this function generic.