All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pu Wen <puwen@hygon.cn>
To: Jan Beulich <JBeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Wei Liu <wei.liu2@citrix.com>,
	xen-devel <xen-devel@lists.xenproject.org>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: Re: [PATCH v2 01/14] x86/cpu: Create Hygon Dhyana architecture support file
Date: Sat, 16 Mar 2019 17:57:58 +0800	[thread overview]
Message-ID: <f723e493-e986-432e-0b4a-e175f0df41c7@hygon.cn> (raw)
In-Reply-To: <5C8B89E7020000780021F38A@prv1-mh.provo.novell.com>

On 2019/3/15 19:18, Jan Beulich wrote:
>>>> On 15.03.19 at 11:17, <puwen@hygon.cn> wrote:
>> On 2019/3/15 1:11, Jan Beulich wrote:
>>>>>> On 21.02.19 at 10:48, <puwen@hygon.cn> wrote:
>>>> +static void __init noinline probe_masking_msrs(void)
>>>> +{
>>>> +	const struct cpuinfo_x86 *c = &boot_cpu_data;
>>>> +
>>>> +	/* Work out which masking MSRs we should have. */
>>>> +	cpuidmask_defaults._1cd =
>>>> +		_probe_mask_msr(MSR_K8_FEATURE_MASK, LCAP_1cd);
>>>> +	cpuidmask_defaults.e1cd =
>>>> +		_probe_mask_msr(MSR_K8_EXT_FEATURE_MASK, LCAP_e1cd);
>>>> +	if (c->cpuid_level >= 7)
>>>> +		cpuidmask_defaults._7ab0 =
>>>> +			_probe_mask_msr(MSR_AMD_L7S0_FEATURE_MASK, LCAP_7ab0);
>>>
>>> There's more relevant code here in the original function.
>>
>> The code is used for family 15h. Hygon CPU do not need it.
> 
> There's a single Fam15 conditional in the middle of the function.
> Everything beyond that is again family-independent.
> 
>>>> +	if (opt_cpu_info) {
>>>> +		printk(XENLOG_INFO "Levelling caps: %#x\n", levelling_caps);
>>>> +		printk(XENLOG_INFO
>>>> +		       "MSR defaults: 1d 0x%08x, 1c 0x%08x, e1d 0x%08x, "
>>>> +		       "e1c 0x%08x, 7a0 0x%08x, 7b0 0x%08x\n",
>>>> +		       (uint32_t)cpuidmask_defaults._1cd,
>>>> +		       (uint32_t)(cpuidmask_defaults._1cd >> 32),
>>>> +		       (uint32_t)cpuidmask_defaults.e1cd,
>>>> +		       (uint32_t)(cpuidmask_defaults.e1cd >> 32),
>>>> +		       (uint32_t)(cpuidmask_defaults._7ab0 >> 32),
>>>> +		       (uint32_t)cpuidmask_defaults._7ab0);
>>>> +	}
>>>> +
>>>> +	if (levelling_caps)
>>>> +		ctxt_switch_masking = hygon_ctxt_switch_masking;
>>>> +}
>>>
>>> This is a lot of duplicated code with only minor differences. I think
>>> you would be better off calling into the AMD original functions.
>>
>> These functions and AMD original ones are static. So Hygon cannot directly
>> call into them. Or we can put them into the common cpu code, but I think
>> it's not good for future maintenance.
> 
> Just make non-static what needs to be, add an amd_ prefix, and
> call it from your code.

That's OK. With this method only init_levelling in amd.c should be added
an amd_ prefix and called by hygon.c.

But I'm afraid Hygon should have its own init functions and not call the
AMD ones. The current Hygon init functions have been heavily stripped
from the original AMD's.

>> There are many codes to support AMD's
>> different families, the family/model/stepping checking are deeply embedded
>> in codes. If we add Hygon family/model/stepping checking in future version,
>> it will make code interleaved together and hard to maintain.
> 
> We can think about adding the duplication when it becomes
> unwieldy to maintain the shared variant.
> 
>>>> +static void init_hygon(struct cpuinfo_x86 *c)
>>>> +{
>>>> +	u32 l, h;
>>>> +	unsigned long long value;
>>>> +
>>>> +	/* Attempt to set lfence to be Dispatch Serialising. */
>>>> +	if (rdmsr_safe(MSR_AMD64_DE_CFG, value))
>>>> +		/* Unable to read.  Assume the safer default. */
>>>> +		__clear_bit(X86_FEATURE_LFENCE_DISPATCH, c->x86_capability);
>>>> +	else if (value & AMD64_DE_CFG_LFENCE_SERIALISE)
>>>> +		/* Already dispatch serialising. */
>>>> +		__set_bit(X86_FEATURE_LFENCE_DISPATCH, c->x86_capability);
>>>
>>> Didn't you cut off too much from the original code (which again
>>> may better be shared, by splitting out into a function)?
>>
>> The cut codes are used for other AMD families except family 17h. Hygon
>> Dhyana is derived from AMD Zen, so we only need the family 17h parts.
>> This also make the init flow minimal.
> 
> How is
> 
> 		else if (wrmsr_safe(MSR_AMD64_DE_CFG,
> 				    value | AMD64_DE_CFG_LFENCE_SERIALISE) ||
> 			 rdmsr_safe(MSR_AMD64_DE_CFG, value) ||
> 			 !(value & AMD64_DE_CFG_LFENCE_SERIALISE))
> 			/* Attempt to set failed.  Assume the safer default. */
> 			__clear_bit(X86_FEATURE_LFENCE_DISPATCH,
> 				    c->x86_capability);
> 		else
> 			/* Successfully enabled! */
> 			__set_bit(X86_FEATURE_LFENCE_DISPATCH,
> 				  c->x86_capability);
> 
> family dependent in any way?

Independent here.

-- 
Regards,
Pu Wen

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2019-03-16 10:03 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-21  9:48 [PATCH v2 00/14] Add support for Hygon Dhyana Family 18h processor Pu Wen
2019-02-21  9:48 ` [PATCH v2 01/14] x86/cpu: Create Hygon Dhyana architecture support file Pu Wen
2019-03-14 17:10   ` Jan Beulich
2019-03-15 10:17     ` Pu Wen
2019-03-15 11:17       ` Jan Beulich
2019-03-16  9:57         ` Pu Wen [this message]
2019-03-18  8:54           ` Jan Beulich
2019-03-19 12:33             ` Pu Wen
2019-03-19 13:02               ` Jan Beulich
2019-03-19 13:34                 ` Pu Wen
2019-02-21  9:48 ` [PATCH v2 02/14] x86/cpu/mtrr: Add Hygon Dhyana support to get TOP_MEM2 Pu Wen
2019-03-15 12:39   ` Jan Beulich
2019-03-16 10:06     ` Pu Wen
2019-03-18  8:57       ` Jan Beulich
2019-03-18 15:51         ` Pu Wen
2019-03-18 16:51           ` Jan Beulich
2019-02-21  9:50 ` [PATCH v2 03/14] x86/cpu/vpmu: Add Hygon Dhyana and AMD Zen support for vPMU Pu Wen
2019-03-15 12:41   ` Jan Beulich
2019-03-16 10:11     ` Pu Wen
2019-03-18  8:59       ` Jan Beulich
2019-03-19 11:32         ` Pu Wen
2019-03-19 12:57           ` Jan Beulich
2019-03-19 13:47             ` Pu Wen
2019-03-19 13:57               ` Jan Beulich
2019-03-19 15:22                 ` Pu Wen
2019-02-21  9:51 ` [PATCH v2 04/14] x86/cpu/mce: Add Hygon Dhyana support to the MCA infrastructure Pu Wen
2019-03-15 12:47   ` Jan Beulich
2019-02-21  9:51 ` [PATCH v2 05/14] x86/spec_ctrl: Add Hygon Dhyana to the respective mitigation machinery Pu Wen
2019-03-15 12:47   ` Jan Beulich
2019-02-21  9:51 ` [PATCH v2 06/14] x86/apic: Add Hygon Dhyana support Pu Wen
2019-03-15 12:48   ` Jan Beulich
2019-02-21  9:52 ` [PATCH v2 07/14] x86/acpi: " Pu Wen
2019-03-15 12:49   ` Jan Beulich
2019-02-21  9:52 ` [PATCH v2 08/14] x86/iommu: " Pu Wen
2019-03-15 13:18   ` Jan Beulich
2019-02-21  9:52 ` [PATCH v2 09/14] x86/pv: Add Hygon Dhyana support to emulate MSRs access Pu Wen
2019-03-15 13:23   ` Jan Beulich
2019-02-21  9:53 ` [PATCH v2 10/14] x86/domain: Add Hygon Dhyana support Pu Wen
2019-03-15 13:24   ` Jan Beulich
2019-02-21  9:53 ` [PATCH v2 11/14] x86/domctl: " Pu Wen
2019-03-15 13:28   ` Jan Beulich
2019-03-16 10:14     ` Pu Wen
2019-02-21  9:53 ` [PATCH v2 12/14] x86/traps: " Pu Wen
2019-02-21  9:54 ` [PATCH v2 13/14] x86/cpuid: " Pu Wen
2019-03-15 13:29   ` Jan Beulich
2019-02-21  9:54 ` [PATCH v2 14/14] tools/libxc: " Pu Wen
2019-02-21 16:37 ` [PATCH v2 00/14] Add support for Hygon Dhyana Family 18h processor Wei Liu
2019-02-22  2:30   ` Pu Wen
2019-02-22 13:21     ` Wei Liu
2019-03-15 13:41 ` Jan Beulich
2019-03-16 10:40   ` Pu Wen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f723e493-e986-432e-0b4a-e175f0df41c7@hygon.cn \
    --to=puwen@hygon.cn \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=roger.pau@citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.