From owner-freebsd-ppc@freebsd.org Thu Jun 9 18:43:52 2016 Return-Path: Delivered-To: freebsd-ppc@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9262FB7055F for ; Thu, 9 Jun 2016 18:43:52 +0000 (UTC) (envelope-from bacon4000@gmail.com) Received: from mail-it0-x22a.google.com (mail-it0-x22a.google.com [IPv6:2607:f8b0:4001:c0b::22a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6476C10D3 for ; Thu, 9 Jun 2016 18:43:52 +0000 (UTC) (envelope-from bacon4000@gmail.com) Received: by mail-it0-x22a.google.com with SMTP id a5so45382650ita.1 for ; Thu, 09 Jun 2016 11:43:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=CT6iAZdJnBfBeD3yDlFxzxvBP3Mhn1lY8HanfVZxjJo=; b=YM5fp4i8rM5/Dtl5pW5Jd8GfiGiPmy3b3hA7Gc8p+cyGMukY9Xcy9PTUDKHC3AKuqE jLI3/yCgA+SNcdnw0OVYMHQg0wITY5OeIowJW2aIX7BP1LRF+E0URHgsbbQ542VET1n9 Lt6kDwHywmto66wmKASxT6pVKVi9HMt84BWZUYwt9Qy74Jz/+rD1TjW4baApduW8Dc86 vv6EyNHItCQljCNh9Pa9d79fTzl+9zbNfC/Z5mYcYsJfwFk3/c+ziRTtzZZvLxI/anMX OePEvCLm7tGolNoCrR/6ZaNwCQkfmudCrwj1UPN1SmjH8VY3coi5v7IhNvEXR91CpBja tihw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=CT6iAZdJnBfBeD3yDlFxzxvBP3Mhn1lY8HanfVZxjJo=; b=BCp3YbMGkwsEyy/uvd764OdMUZ9ZEzr4INEra4xGxDAq0ZrxNx35qb4FYl3nWqWNGb +2FLNAV5aAMyJ7zWPT1EDlaiUrF3v8+IEc4qO/ntSCHBkWgqqfwnJuCsgd4RrBi6mI1z 9VZnfR0hRP7bj6YTVGJHYgewFDt3aQIYzNJSy4TfSOz9Q/sSlMbL2bUVJfSlasm1FYS/ CVYfopd9GjQbYgAtkBwcy2ej5z1W6g5HoZtr2pp5E48pwEzOAN6eeEmj2jb6q6i4q9/3 HNat3/7MD4zjztoPQcgSTljbh5T5VqJo/ExrnF6zKJq9j428hPyIguQkSCHeOFS7e8xh Hb2g== X-Gm-Message-State: ALyK8tLtNsSVF+Y746gEuWPaZ7xa55oydfnp9zySbi2JX+d6tlf9u22nA8/xew3HKYRQMQ== X-Received: by 10.36.149.137 with SMTP id m131mr25361958itd.94.1465497831731; Thu, 09 Jun 2016 11:43:51 -0700 (PDT) Received: from imacbsd.acadix.biz (cpe-174-102-163-140.wi.res.rr.com. [174.102.163.140]) by smtp.gmail.com with ESMTPSA id b190sm3764054itc.3.2016.06.09.11.43.51 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 09 Jun 2016 11:43:51 -0700 (PDT) Subject: Re: Detecting Power7 in C To: Justin Hibbits References: <765d3292-78ae-8b02-8a5b-43bafc68d9e8@gmail.com> <3FD85BCC-4304-4DBA-8B72-5A6A79C120A6@gmail.com> Cc: "freebsd-ppc@freebsd.org" From: Jason Bacon Message-ID: Date: Thu, 9 Jun 2016 13:43:50 -0500 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: <3FD85BCC-4304-4DBA-8B72-5A6A79C120A6@gmail.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-ppc@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Porting FreeBSD to the PowerPC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Jun 2016 18:43:52 -0000 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 #include #include #include #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