Skip to content

Commit

Permalink
Support for multi socket systems (only information gathering, not pri…
Browse files Browse the repository at this point in the history
…nting)
  • Loading branch information
Dr-Noob committed Jun 22, 2020
1 parent 698274e commit 92992be
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Peak FLOPS: 512 GFLOP/s(in simple precision)
***/

static const char* VERSION = "0.49";
static const char* VERSION = "0.410";

void print_help(char *argv[]) {
printf("Usage: %s [--version] [--help] [--style STYLE]\n\
Expand Down
30 changes: 25 additions & 5 deletions src/standart.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
#include <assert.h>
#include <stdbool.h>

#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#include "udev.h"
#endif

#include "standart.h"
#include "cpuid.h"
#include "global.h"

#ifndef _WIN32
#include "udev.h"
#endif

#define VENDOR_INTEL_STRING "GenuineIntel"
#define VENDOR_AMD_STRING "AuthenticAMD"

Expand Down Expand Up @@ -69,9 +72,11 @@ struct frequency {
};

struct topology {
int64_t total_cores;
uint32_t physical_cores;
uint32_t logical_cores;
uint32_t smt;
uint32_t smt;
uint32_t sockets;
bool ht;
};

Expand Down Expand Up @@ -276,6 +281,21 @@ struct topology* get_topology_info(struct cpuInfo* cpu) {
return NULL;
}

// Ask the OS the total number of cores it sees
// If we have one socket, it will be same as the cpuid,
// but in dual socket it will not!
#ifdef _WIN32
SYSTEM_INFO info;
GetSystemInfo(&info);
topo->total_cores = info.dwNumberOfProcessors;
#else
if((topo->total_cores = sysconf(_SC_NPROCESSORS_ONLN)) == -1) {
perror("sysconf");
topo->total_cores = topo->logical_cores; // fallback
}
#endif
topo->sockets = topo->total_cores / topo->smt / topo->physical_cores; // Idea borrowed from lscpu

return topo;
}

Expand Down

0 comments on commit 92992be

Please sign in to comment.