linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Len Brown <lenb@kernel.org>
To: Andi Kleen <andi@firstfloor.org>
Cc: Greg Kroah-Hartman <gregkh@suse.de>,
	linux-pm@lists.linux-foundation.org,
	linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org,
	x86@kernel.org
Subject: Re: [PATCH RESEND] tools: add power/x86/x86_energy_perf_policy to program MSR_IA32_ENERGY_PERF_BIAS
Date: Mon, 22 Nov 2010 15:13:24 -0500 (EST)	[thread overview]
Message-ID: <alpine.LFD.2.00.1011221348200.19247@x980> (raw)
In-Reply-To: <8739r0rxlz.fsf@basil.nowhere.org>

Hi Andy,

Thank you for the review!

responses below.

> > +install :
> > +	install x86_energy_perf_policy /usr/bin/x86_energy_perf_policy
> 
> It's not clear to me how this Makefile ensures it's only
> build on x86. 
> 
> If someone on another architecture does a full tools build
> in the future (I think that is not wired up yet, but should
> eventually) such a mechanism would be needed.

Per the comments from Andrew and others, the concept of a
"full tools build" doesn't actually exit (yet).

So I guess the only assurance that somebody not on x86 would run
make in this directory this utility lives in tools/power/x86/

Note that there are other utilities under tools
which have no Makefile at all...

> ...I would prefer a manpage

I'll be happy to write a manpage.
Is there good example I should follow?

> > +cmdline(int argc, char **argv) {
> 
> No type?

okay,  now void.

> > +	while ((opt = getopt(argc, argv, "+rvc:")) != -1) {
> 
> Maybe it's me, but I prefer having long options too (getopt_long)
> These are easier to memorize.

I'm not inclined to bother, as the use-case for this utility
is to be invoked by another program, and the options available
are really there just for verification/debugging, and don't
really merit being memorized by a human after that task.

> An obvious improvement would be to put the exit() into usage()

done.

> > +			new_bias = atoll(argv[optind]);
> 
> If you used strtoull() you could actually check if the input
> is really a number (end == argv[optind])

done.

> > +	asm("cpuid" : "=a" (max_level), "=b" (ebx), "=c" (ecx),
> > +		"=d" (edx) : "a" (0));
> 
> Strictly for 386/early 486 you would need to check if cpuid
> is available using pushf too. Perhaps it's safer to use cpuinfo

Meh, maybe simpler to crash on 486 and earlier?:-)
I'm not fond of parsing /proc/cpuinfo.

> > +check_dev_msr() {
> 
> Return type missing again

routine deleted.

> > +	struct stat sb;
> > +
> > +	if (stat("/dev/cpu/0/msr", &sb)) {
> > +		printf("no /dev/cpu/0/msr\n");
> 
> This will fail if we eventually implement cpu 0 hotplug...
> Better readdir or similar.

simpler to delete check_dev_msr() and stumble forward
assuming /dev/cpu/*/msr exists, and print a message and
exit if it doesn't.

> > +		printf("Try \"# modprobe msr\"\n");
> > +		exit(-5);
> 
> Again -5 is unusual.

okay, I canged all the exits to 1.

> > +	sprintf(msr_path, "/dev/cpu/%d/msr", cpu);
> > +	fd = open(msr_path, O_RDONLY);
> > +	if (fd < 0) {
> > +		perror(msr_path);
> > +		exit(-1);
> 
> This should be a soft error because the CPU can go away
> any time.

In the highly unlikely scenario that somebody uses
the -r option to excerise the read-only code,
and simultaneously invokes and completes a cpu hot remove
during the execution of this utility,
I think the utility exiting is just as useful,
and less complicated, than handling soft error.
Since in either case, the user would probably
simply re-invoke the utility to see what the
current state of the settled machine is.

> > +/*
> > + * run func() on every cpu in /dev/cpu
> > + */
...
> > +	fp = fopen(proc_stat, "r");
> 
> Using /proc/stat to get the number of CPUs is unusual
> and you don't handle holes in the cpu numbers which
> can happen due to hotplug.

The code does handle holes in cpu number namespace.

The "num_cpus" variable was a hold-over from
an older version that did not, and so I've deleted it.

> I would just readdir or fnmatch the MSR /dev/cpu/* directories.

I used to do that, but Arjan convinced me to use /proc/stat.
turbostat, rdmsr, and wrmsr all use /proc/stat.

thanks,
-Len Brown, Intel Open Source Technology Center





  reply	other threads:[~2010-11-22 20:13 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-16 21:05 RFC: /sys/power/policy_preference Len Brown
2010-06-17  6:03 ` [linux-pm] " Igor.Stoppa
2010-06-17 19:00   ` Len Brown
2010-06-17 16:14 ` Victor Lowther
2010-06-17 19:02   ` Len Brown
2010-06-17 22:23     ` Victor Lowther
2010-06-18  5:56       ` Len Brown
2010-06-18 11:55         ` Victor Lowther
2010-06-19 15:17   ` Vaidyanathan Srinivasan
2010-06-19 19:04     ` Rafael J. Wysocki
2010-06-17 20:48 ` Mike Chan
2010-06-18  6:25   ` Len Brown
2010-06-21 20:10 ` [linux-pm] " Dipankar Sarma
2010-09-28 16:17 ` x86_energy_perf_policy.c Len Brown
2010-10-23  4:40   ` [PATCH] tools: add x86_energy_perf_policy to program MSR_IA32_ENERGY_PERF_BIAS Len Brown
2010-10-27  3:23     ` Andrew Morton
2010-10-27  6:01       ` Ingo Molnar
2010-10-27 11:43         ` Arnaldo Carvalho de Melo
2010-11-15 16:07     ` [PATCH RESEND] tools: add power/x86/x86_energy_perf_policy " Len Brown
2010-11-17 11:35       ` Andi Kleen
2010-11-22 20:13         ` Len Brown [this message]
2010-11-22 20:33           ` Andi Kleen
2010-11-23  4:48             ` Len Brown
2010-11-24  5:31       ` [PATCH v2] tools: create power/x86/x86_energy_perf_policy Len Brown
2010-11-25  5:52         ` Chen Gong
2010-11-25  8:59           ` Chen Gong

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=alpine.LFD.2.00.1011221348200.19247@x980 \
    --to=lenb@kernel.org \
    --cc=andi@firstfloor.org \
    --cc=gregkh@suse.de \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=x86@kernel.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 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).