linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org,
	tsbogend@alpha.franken.de, linux-api@vger.kernel.org
Subject: Re: [PATCH v2] MIPS: Expose prid and globalnumber to sysfs
Date: Fri, 12 Aug 2022 09:43:24 -0700	[thread overview]
Message-ID: <ac5e544a-a9d7-37c7-3d0b-65e706d544a0@gmail.com> (raw)
In-Reply-To: <2ED0B1C9-07AB-4DE3-BC85-F490FA94785F@flygoat.com>

On 8/12/22 03:29, Jiaxun Yang wrote:
> 
> 
>> 2022年8月12日 03:21,Florian Fainelli <f.fainelli@gmail.com 
>> <mailto:f.fainelli@gmail.com>> 写道:
>>
>>
>>
>> On 8/11/2022 3:12 AM, Jiaxun Yang wrote:
>>> Some application would like to know precise model and rev of processor
>>> to do errata workaround or optimization.
>>> Expose them in sysfs as:
>>> /sys/devices/system/cpu/cpuX/regs/identification/prid
>>> /sys/devices/system/cpu/cpuX/regs/identification/globalnumber
>>> Reusing AArch64 CPU registers directory.
>>> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com 
>>> <mailto:jiaxun.yang@flygoat.com>>
>>> ---
>>> v2: Drop static qualifier for kobj (gregkh)
>>> ---
>>>  .../ABI/testing/sysfs-devices-system-cpu      | 11 +++
>>>  arch/mips/kernel/topology.c                   | 96 +++++++++++++++++++
>>>  2 files changed, 107 insertions(+)
>>> diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu 
>>> b/Documentation/ABI/testing/sysfs-devices-system-cpu
>>> index 5bf61881f012..adf855e7bb9b 100644
>>> --- a/Documentation/ABI/testing/sysfs-devices-system-cpu
>>> +++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
>>> @@ -512,6 +512,17 @@ Description:information about CPUs heterogeneity.
>>> cpu_capacity: capacity of cpuX.
>>>  +What:/sys/devices/system/cpu/cpuX/regs/
>>> +/sys/devices/system/cpu/cpuX/regs/identification/
>>> +/sys/devices/system/cpu/cpuX/regs/identification/prid
>>> +/sys/devices/system/cpu/cpuX/regs/identification/globalnumber
>>> +Date:Augest 2022
>>
>> typo: August
> 
> Thanks, good catch :-)
> 
>>
>>> +Contact:Linux MIPS Kernel Mailing list <linux-mips@vger.kernel.org 
>>> <mailto:linux-mips@vger.kernel.org>>
>>> +Description:MIPS CPU registers
>>> +
>>> +'identification' directory exposes the Processor ID and Global Number
>>> +registers for identifying model and revision of the CPU.
>>> +
>>>  What:/sys/devices/system/cpu/vulnerabilities
>>> /sys/devices/system/cpu/vulnerabilities/meltdown
>>> /sys/devices/system/cpu/vulnerabilities/spectre_v1
>>> diff --git a/arch/mips/kernel/topology.c b/arch/mips/kernel/topology.c
>>> index 9429d85a4703..0e3730f3c00f 100644
>>> --- a/arch/mips/kernel/topology.c
>>> +++ b/arch/mips/kernel/topology.c
>>> @@ -5,6 +5,8 @@
>>>  #include <linux/node.h>
>>>  #include <linux/nodemask.h>
>>>  #include <linux/percpu.h>
>>> +#include <linux/seq_file.h>
>>> +#include <linux/smp.h>
>>>    static DEFINE_PER_CPU(struct cpu, cpu_devices);
>>>  @@ -26,3 +28,97 @@ static int __init topology_init(void)
>>>  }
>>>    subsys_initcall(topology_init);
>>> +
>>> +static struct kobj_type cpuregs_kobj_type = {
>>> +.sysfs_ops = &kobj_sysfs_ops,
>>> +};
>>> +
>>> +struct cpureg {
>>> +struct kobject kobj;
>>> +struct cpuinfo_mips *info;
>>> +};
>>> +DEFINE_PER_CPU(struct cpureg, cpuregs);
>>> +
>>> +#define kobj_to_cpureg(kobj)container_of(kobj, struct cpureg, kobj)
>>> +#define CPUREGS_ATTR_RO(_name, _field)\
>>> +static ssize_t _name##_show(struct kobject *kobj,\
>>> +struct kobj_attribute *attr, char *buf)\
>>> +{\
>>> +struct cpuinfo_mips *info = kobj_to_cpureg(kobj)->info;\
>>> +\
>>> +return sprintf(buf, "0x%08x\n", info->_field);\
>>
>> Would not you be able to simplify this greatly with just:
>>
>> struct cpuinfo_mips *info = current_cpu_data;
> 
> Because some fields in PRID and globalnumber are not consistent between 
> cores
> so it needs to be per CPU.

Yes my bad, I was thinking that you could simplify things by always 
getting the registers of the CPU you are running on, but you need to 
create those attributes for each CPU in the system and ensure that they 
do resolve to the actual cpuinfo_mips of said CPU, such that when you do:

cat /sys/device/system/cpu/cpu*/regs/prid

we do return the actual information of that CPU number, not the one from 
the CPU we are on.

Thanks!
-- 
Florian

      parent reply	other threads:[~2022-08-12 16:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-11 10:12 [PATCH v2] MIPS: Expose prid and globalnumber to sysfs Jiaxun Yang
2022-08-11 10:22 ` Greg KH
2022-08-12  2:21 ` Florian Fainelli
     [not found]   ` <2ED0B1C9-07AB-4DE3-BC85-F490FA94785F@flygoat.com>
2022-08-12 16:43     ` Florian Fainelli [this message]

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=ac5e544a-a9d7-37c7-3d0b-65e706d544a0@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=jiaxun.yang@flygoat.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=tsbogend@alpha.franken.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).