From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754433AbcDGFEl (ORCPT ); Thu, 7 Apr 2016 01:04:41 -0400 Received: from mail-by2on0069.outbound.protection.outlook.com ([207.46.100.69]:64713 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750817AbcDGFEj (ORCPT ); Thu, 7 Apr 2016 01:04:39 -0400 Authentication-Results: spf=none (sender IP is 165.204.84.221) smtp.mailfrom=amd.com; alien8.de; dkim=none (message not signed) header.d=none;alien8.de; dmarc=permerror action=none header.from=amd.com; X-WSS-ID: 0O58ZFM-07-L07-02 X-M-MSG: Date: Thu, 7 Apr 2016 13:05:52 +0800 From: Huang Rui To: Guenter Roeck CC: Jean Delvare , , , Borislav Petkov , "Sherry Hurwitz" Subject: Re: [PATCH v6 2/6] hwmon: (fam15h_power) Add compute unit accumulated power Message-ID: <20160407050551.GA30309@hr-amur2> References: <1459928655-6071-1-git-send-email-ray.huang@amd.com> <1459928655-6071-3-git-send-email-ray.huang@amd.com> <20160406153025.GA16343@roeck-us.net> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20160406153025.GA16343@roeck-us.net> User-Agent: Mutt/1.5.21 (2010-09-15) X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:165.204.84.221;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(428002)(189002)(199003)(24454002)(83506001)(19580395003)(50466002)(4326007)(2950100001)(2906002)(47776003)(189998001)(19580405001)(15975445007)(77096005)(50986999)(54356999)(81166005)(46406003)(76176999)(586003)(33656002)(106466001)(11100500001)(164054004)(101416001)(575784001)(1096002)(97756001)(1220700001)(23726003)(92566002)(87936001)(105586002)(5008740100001)(110136002)(33716001)(86362001)(4001350100001)(107986001);DIR:OUT;SFP:1101;SCL:1;SRVR:BLUPR12MB0706;H:atltwp01.amd.com;FPR:;SPF:None;MLV:sfv;MX:1;A:1;LANG:en; X-MS-Office365-Filtering-Correlation-Id: 5bf4b7c2-3bdd-45fc-bd47-08d35ea21db7 X-Microsoft-Exchange-Diagnostics: 1;BLUPR12MB0706;2:PWQdhK8PssgMhhjR6rNmjKUhb+s5M+dujtfQtBJJZ5qxngVYgWu7d74+QfB/7n4XacpI2xeecmxxA7Hd0QL8/JJg4V4RMkkxWbYwJoJovX2Djrmzy6RBaHfB30oOVgqybqETn/8p6OxVGmHmKfJDnpK3MagYGMH0YPHL237owUcxaO8vZYxUzeAo89PAIsUV;3:OavDGcsQJlGLwJfnxZTIX4d3YiXPtZ9a11ii+I1TtMex03pS1u4bjLR/R6eyIf38bRXzvU/cYMyKvnMUgASg30XASgrQDdPeBeS+9ej63wrflFvCoaWvK5dJxGZ0QZI5wLUvdekNpu7vbngh6u6pqky+U8/djjbUyMmU0NpJwRJKCt/9TjmBU+JPqDuzvwOF8ooXeHvAWdfayFvria1AlbTZvUWapFu3y0noHFohCg0=;25:v4M+bMpkR68BXKSbbpmN24CqLziD41taJD7SmG4NZ/S4zcrZdB4lQe1QkY/mnbRuGh3gEO3zNjBEYoqpBjuG68IECQ3Gcw9MBHuZzF9ap+WopKKQG1qPCnOeSqGbbkLmJMUVoT3J+2Zu0k5riEqHG4oLSDQ4Sl6ewNLhHXW3BoK1zUtaMbqGR8vdJ7FHDXvjoCsn1jHtxoa4nt/CuMMX0G7du4J37lrAdkc+6+NMncttbLLP/nIJvgajDAdH+SGUgPKTEEQIk91CklxfAFmVy9cWaGrJH0QNL1CCYhToA1+kRF7CK3liiVliWPAokvgTLIebwcR67iGHEy6o88wQwQ== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR12MB0706; X-Microsoft-Exchange-Diagnostics: 1;BLUPR12MB0706;20:WKhqUXiJ2p3hmhe0GU4obm75yeR3uRiQz66ZV0cVnuYikZwIzY6NHLfmbi41InEZDgFWYEOAEbSERhf/zfWRUiQ4N6dbaHl/ohdEVf2sErnysbXQjz1s2WzN4mcnFnKQphEJrlYizl0/cyBA/Qv6cYHXfZZlIhzK+sMFiBr15eJDqbsyr3NhrZy2BusaHhS7XpGmFgAHEpXCLTaoYIPfcUQC+aI79TYAxFZG+2UZmk89240oXxWHciNHFrJLXQ6igbbevm4+N1N8YWIe2oFZXVlKqWgmC8RMKXxB28eBpdB+r+BAdjW+g5A5gInxf1H5jNpLbaKakdzy6RUqFYHV6Eemu+0IRowMeBHY2ICt+42B8XNaJcL8aJgMgT3Rxy5AHqsZcW1s06o5azeTjjJSidNdJHyelLnrz13BRx5FT5oeY+YRc5twL5cDZ+zA0tf/TAJYmmZL/MaGMNIm15+n2tPhQrMVA5Wqw1FmUWXPJ/0L+Xf8t6jA60BpMhynl0Lf X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(13018025)(5005006)(13017025)(13015025)(8121501046)(13024025)(13023025)(10201501046)(3002001);SRVR:BLUPR12MB0706;BCL:0;PCL:0;RULEID:;SRVR:BLUPR12MB0706; X-Microsoft-Exchange-Diagnostics: 1;BLUPR12MB0706;4:LMMIGwg4C0eoon2UdLsjms1aCx/EK8IKuO+zYbc+rVH1grQSKeNy4UrGmyZrJuOFqWgNwr33lcemmxVN5+xcFTvrhDgNjCFPSN1FFrkoLwvjBmLtSO+yh535k+YMiLah97xG73s5Kb6FDT255EhDfKJiAKUzVNa6+WkmMqAUPpmV9uKOXDxAPr8EvjjRGlCZSYzmFzG5UCtKfP7cj+Q2CyIYVqWyYsqBGbpvYOV4CQjS2Ubw+uEBmVsliEqwCuu6wc4PtIA2EuyCluZCrh68MrVMQ4aRUmbOW/o0HOIpdQeZowmSOx2GvP5mQhFf3bBSDh1cjOU5BRH72G+6L2SP+2pD6+vPLE732NgKYcQkynxxnoarSlqVQ5W01i/QbYDpRAx4mNt4hpthzhW0SU0x1dzjJ+s8n03LFP9g9rd0a5B+iyOI4nE1HllFc1z1NpRxxvKKB1p13vCCga4tHPVxIw== X-Forefront-PRVS: 0905A6B2C7 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BLUPR12MB0706;23:rFKTgUh5ho3YwyZTRlbGFOSXV1Vf2TMONPMRf9GY+?= =?us-ascii?Q?2O1WFq6seECF6LVQF8ztBXD8HE8Lakq7FbxJHuaNbi6oWcVpTIyp+Y4F6I5C?= =?us-ascii?Q?nEBI6Iq27IJbhauFI5ClwDbDfitGZE1We8J+bbYhaIW9KKd268pnfXDsrw/J?= =?us-ascii?Q?p+N1Qf0LAs9Xwjvx4i/IksUmhtlq4z7dnwpbSqs7bLMcj/us5IenYP6jJzMo?= =?us-ascii?Q?IJSY5Nu0aY3zx2geysnC4ic1E+YhroANZOiqP0lgaRUowJU+QyCtHVqSbKNR?= =?us-ascii?Q?ff9NQBaX3OxaWgTZQPecyYfaKngK32MFnb0xuvluFUJzG19G2NPWI3MWktSt?= =?us-ascii?Q?6piFu12eZKbAGJvcGbFysYr1QQI4/WgUhLZS9QmFR8XHD0P37AytY0c380xW?= =?us-ascii?Q?qnQZ1gdQR66NTmBNoCl+WRYEy7bthi4XkQsZ8GZPxA4e86+x7cfiA7BkLwTF?= =?us-ascii?Q?FUqqWlYXopaYt39/YE+z4WQf/IicMC1vwWbHIqfuxFlNcGSpr7NF1Lz7pb26?= =?us-ascii?Q?Nb79qV7DucNpXybBulbUmzNzUJshyalUSqe7ziEQDZNH13w5VYs5RLA9Sdyx?= =?us-ascii?Q?ans0yfjoPSFbYAIfApRDIzvBvXSe+ZwyjK3Kp5q1gFi8dkqSD0kO7HDNjFrL?= =?us-ascii?Q?Z3l11m3G0hfl0DfEUdu9io9oJ0ZxsQ/00dtdtaZBfw9QQvm67WwmaLiAfXvd?= =?us-ascii?Q?ImrC0LsUKIj10qllTZooXSzplr6xjRH+So6BkSdKbKJjV616peIObMj1WluT?= =?us-ascii?Q?59iWxRK2TJDMbSEY3NlzmZmHrSYGun6DhuZ58SaOuLic6272PuSU5jGJir/v?= =?us-ascii?Q?MApggjzmFvXRhxSti3HLa2AQrsN7otEv6plfTQvoQvvbQ3ydnfWhuSmAFDqS?= =?us-ascii?Q?jTi28i3t/5ZJPxXQ8Fb2melPPAfehpdGvNu1WcYBfGhgKHOxT6JG6icMBTFs?= =?us-ascii?Q?GveyY6OjWQSxClOGIJfr+s9tPnE8f5TQIwvk4nDCLrsUyb2mHFLxoD3W/xOa?= =?us-ascii?Q?mxiiq7T1Ifz3Kpm0xx2xWTD7PSCBZn/JklazdGZNaxfGi4V8auNfX1avebH9?= =?us-ascii?Q?syUoumuwKcdFryCF7UhVrPce6zwbvZSWlNm0srT/GauNfyCXA=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;BLUPR12MB0706;5:J/rLrggjeQ/5w2i2SHYyjbtcKGuZHmZWTUazqO77aXGPqzR9ba0bMjpcLH60RpXeX4Sqm4QAtA9i4lt62C6D4wvRsdQIg0pVBLLrB3fYrLataqQmCheezTjWks/jqC+D81gbo6A8/2Jiq6mt4jNLcQ==;24:WcKs1YK5ppOkTljq7O2tv8ecGARu8lknm1RJ7X8osWbT7PxUIaYChWF99LsGg+SGZfbtmutm+jz/RnuNQMPBu4SA04U9GeC02SxSJbWgBsU=;20:pRVTEPApZw0HEUwKWH0baALuhOS+MF2riXiietj8oQwzx+OjpwA+jMWMceD1z15pYApThx7aVbRnGFeQJ7+Krnp1iY27Pnffzhxt+qx72SlT+oCuu0ZQNPKH0FCp7H+I1WU7bK15fBqXJ2oWlLuAaYwx28Woi3sEUnc60BNckCxtmgErHh0NkHRieJgMktg2JOjX8rhUVtnnnkRyA5rouYLJPCm6lGdktiUE+30dPcFDYjjFHSh/v7fxGRFegzl7 SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Apr 2016 05:04:36.1446 (UTC) X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.221];Helo=[atltwp01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0706 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 06, 2016 at 08:30:25AM -0700, Guenter Roeck wrote: > On Wed, Apr 06, 2016 at 03:44:11PM +0800, Huang Rui wrote: > > > > +static void do_read_registers_on_cu(void *_data) > > +{ > > + struct fam15h_power_data *data = _data; > > + int cpu, cu; > > + > > + cpu = smp_processor_id(); > > + > > Is this function now defined in non-SMP code ? If so, can you point me to the > patch or branch introducing it ? It doesn't seem to be in mainline or in -next > unless I am missing it. > In include/linux/smp.h #else /* !SMP */ static inline void smp_send_stop(void) { } /* * These macros fold the SMP functionality into a single CPU system */ #define raw_smp_processor_id() 0 ... /* * smp_processor_id(): get the current CPU ID. * * if DEBUG_PREEMPT is enabled then we check whether it is * used in a preemption-safe way. (smp_processor_id() is safe * if it's used in a preemption-off critical section, or in * a thread that is bound to the current CPU.) * * NOTE: raw_smp_processor_id() is for internal use only * (smp_processor_id() is the preferred variant), but in rare * instances it might also be used to turn off false positives * (i.e. smp_processor_id() use that the debugging code reports but * which use for some reason is legal). Don't use this to hack around * the warning message, as your code might not work under PREEMPT. */ #ifdef CONFIG_DEBUG_PREEMPT extern unsigned int debug_smp_processor_id(void); # define smp_processor_id() debug_smp_processor_id() #else # define smp_processor_id() raw_smp_processor_id() #endif Actually smp_processor_id() should returns 0 if we disable CONFIG_SMP. > > + /* > > + * With the new x86 topology modelling, cpu core id actually > > + * is compute unit id. > > + */ > > + cu = cpu_data(cpu).cpu_core_id; > > + > > + rdmsrl_safe(MSR_F15H_CU_PWR_ACCUMULATOR, &data->cu_acc_power[cu]); > > +} > > + > > +/* > > + * This function is only able to be called when CPUID > > + * Fn8000_0007:EDX[12] is set. > > + */ > > +static int read_registers(struct fam15h_power_data *data) > > +{ > > + int this_cpu, ret, cpu; > > + int core, this_core; > > + cpumask_var_t mask; > > + > > + ret = zalloc_cpumask_var(&mask, GFP_KERNEL); > > + if (!ret) > > + return -ENOMEM; > > + > > + get_online_cpus(); > > + this_cpu = smp_processor_id(); > > + > > + /* > > + * Choose the first online core of each compute unit, and then > > + * read their MSR value of power and ptsc in a single IPI, > > + * because the MSR value of CPU core represent the compute > > + * unit's. > > + */ > > + core = -1; > > + > > + for_each_online_cpu(cpu) { > > + this_core = topology_core_id(cpu); > > + > > + if (this_core == core) > > + continue; > > + > > + core = this_core; > > + > Sorry if I missed some context - is it guaranteed that all cores in the same > compute unit are returned next to each other from for_each_online_cpu() ? > Yes, there is a documentation which introduced from v4.6-rc2: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=f7be8610bca88e59dd2fd5d98fcbc5031ef0e079 - topology_core_id(); The ID of the core to which a thread belongs. It is also printed in /proc/cpuinfo "core_id." ... AMD nomenclature for CMT systems: [node 0] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 0 -> [Compute Unit Core 1] -> Linux CPU 1 -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 2 -> [Compute Unit Core 1] -> Linux CPU 3 ray@hr-ub:~/tip$ cat /proc/cpuinfo | grep "core id" core id : 0 core id : 0 core id : 1 core id : 1 "this_core" here actually means the [Compute Unit] id which current [Compute Unit Core] belongs to. And "cpu" here means the [Compute Unit Core]. Thanks, Rui