Date: Thu, 9 Jun 2016 13:43:50 -0500 From: Jason Bacon <bacon4000@gmail.com> To: Justin Hibbits <chmeeedalf@gmail.com> Cc: "freebsd-ppc@freebsd.org" <freebsd-ppc@freebsd.org> Subject: Re: Detecting Power7 in C Message-ID: <b182ab99-1446-1426-defe-b56c9e21bf9a@gmail.com> In-Reply-To: <3FD85BCC-4304-4DBA-8B72-5A6A79C120A6@gmail.com> References: <765d3292-78ae-8b02-8a5b-43bafc68d9e8@gmail.com> <3FD85BCC-4304-4DBA-8B72-5A6A79C120A6@gmail.com>
index | next in thread | previous in thread | raw e-mail
On 06/09/16 10:47, Justin Hibbits wrote:
> On Jun 9, 2016, at 9:09 AM, Jason Bacon wrote:
>
>>
>> I'm porting the SLURM task/affinity plugin to FreeBSD and wondering
>> what's the best way to detect whether we're running on a power7
>> processor.
>>
>> The Linux code is below. I could do something similar with
>> dmesg.boot on FreeBSD, but hoping there's a more elegant way within a
>> C program.
>>
>> If I have to use dmesg.boot, what string would I be looking for? I
>> don't have a power7 installation at the moment.
>>
>> Thanks,
>>
>> Jason
>>
>> FILE *cpu_info_file;
>>
>> char buffer[128];
>> char* _cpuinfo_path = "/proc/cpuinfo";
>> cpu_info_file = fopen(_cpuinfo_path, "r");
>> if (cpu_info_file == NULL) {
>> error("_get_is_power: error %d opening %s",
>> errno,
>> _cpuinfo_path);
>> return false; /* assume not power processor */
>> }
>>
>> is_power = 0;
>> while (fgets(buffer, sizeof(buffer), cpu_info_file) !=
>> NULL) {
>> if (strstr(buffer, "POWER7")) {
>> is_power = 1;
>> break;
>> }
>> }
>> fclose(cpu_info_file);
>
> You can use the hw.model sysctl. For POWER7, the string you would
> receive is "POWER7". For all the model strings you can get, see the
> strings in the models[] table in sys/powerpc/powerpc/cpu.c .
>
> - Justin
Very nice. Confirmed with the test driver below...
Thanks,
Jason
#include <stdio.h>
#include <sysexits.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#define BUFFLEN 128
int main(int argc,char *argv[])
{
char buff[BUFFLEN+1];
size_t len = BUFFLEN;
sysctlbyname("hw.model", buff, &len, NULL, 0);
puts(buff);
return EX_OK;
}
--
All wars are civil wars, because all men are brothers ... Each one owes
infinitely more to the human race than to the particular country in
which he was born.
-- Francois Fenelon
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?b182ab99-1446-1426-defe-b56c9e21bf9a>
