From: Jan Stancek <jstancek@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] open_posix_testsuite: add set_affinity_single()
Date: Thu, 12 Nov 2015 08:41:15 -0500 (EST) [thread overview]
Message-ID: <1524656392.7427722.1447335675915.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <20151112130952.GB19653@rei.lan>
----- Original Message -----
> From: "Cyril Hrubis" <chrubis@suse.cz>
> To: "Jan Stancek" <jstancek@redhat.com>
> Cc: ltp@lists.linux.it
> Sent: Thursday, 12 November, 2015 2:09:52 PM
> Subject: Re: [LTP] [PATCH] open_posix_testsuite: add set_affinity_single()
>
> Hi!
> > +static int get_present_cpu_from_sysfs(void)
> > +{
> > + FILE *f;
> > + int cpu = -1;
> > +
> > + f = fopen("/sys/devices/system/cpu/present", "r");
> > + if (!f)
> > + return -1;
> > + fscanf(f, "%d", &cpu);
> > + fclose(f);
> > +
> > + return cpu;
> > +}
> > +
> > +static int get_present_cpu_from_cpuinfo(void)
> > +{
> > + FILE *f;
> > + int cpu = -1;
> > + char line[4096];
> > +
> > + f = fopen("/proc/cpuinfo", "r");
> > + if (!f)
> > + return -1;
> > +
> > + while (!feof(f)) {
> > + if (!fgets(line, sizeof(line), f))
> > + return -1;
> > + /*
> > + * cpuinfo output is not consistent across all archictures,
> > + * it can be "processor : N", but for example on s390
> > + * it's: "processor N: ...", so ignore any non-number
> > + * after "processor"
> > + */
> > + if (sscanf(line, "processor%*[^0123456789]%d", &cpu) == 1)
> > + break;
> > + }
> > + fclose(f);
> > +
> > + return cpu;
> > +}
> > +
> > +static int set_affinity_single(void)
> > +{
> > + int cpu;
> > +
> > + cpu = get_present_cpu_from_sysfs();
> > + if (cpu < 0)
> > + cpu = get_present_cpu_from_cpuinfo();
>
> We should probably fallback here to cpu = 0 in case that we have failed
> to parse the cpuinfo. Not that it's likely to happen.
>
> So I would do here:
>
> cpu = get_present_cpu_from_sysfs();
>
> if (cpu >= 0)
> goto set_affinity;
>
> cpu = get_present_cpu_from_cpuinfo();
>
> if (cpu >= 0)
> goto set_affinity;
>
> fprintf(stderr, "WARNING: Failed to detect present cpu using cpu=0\n");
>
> cpu = 0;
>
> set_affinity:
> return set_affinity(cpu);
>
> > + return set_affinity(cpu);
> > +}
> > +
> > #else
> > static int set_affinity(int cpu)
> ^
> You should also rename this stub for
> non-linux OSes.
>
> Otherwise it looks good, acked.
Pushed with changes you suggested.
Regards,
Jan
>
> --
> Cyril Hrubis
> chrubis@suse.cz
>
prev parent reply other threads:[~2015-11-12 13:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-12 12:45 [LTP] [PATCH] open_posix_testsuite: add set_affinity_single() Jan Stancek
2015-11-12 13:05 ` Jan Stancek
2015-11-12 13:09 ` Cyril Hrubis
2015-11-12 13:41 ` Jan Stancek [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=1524656392.7427722.1447335675915.JavaMail.zimbra@redhat.com \
--to=jstancek@redhat.com \
--cc=ltp@lists.linux.it \
/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.