static int mlx4_is_sandy_bridge(int *num_cores) { char line[128]; FILE *fd; int rc = 0; int cur_cpu_family = -1; int cur_cpu_model = -1; fd = fopen("/proc/cpuinfo", "r"); if (!fd) return 0; *num_cores = 0; while (fgets(line, 128, fd)) { int value; /* if this is information on new processor */ if (!strncmp(line, "processor", 9)) { ++*num_cores; cur_cpu_family = -1; cur_cpu_model = -1; } else if (!strncmp(line, "cpu family", 10)) { if ((cur_cpu_family < 0) && (!read_number_from_line(line, &value))) cur_cpu_family = value; } else if (!strncmp(line, "model", 5)) { if ((cur_cpu_model < 0) && (!read_number_from_line(line, &value))) cur_cpu_model = value; } /* if this is a Sandy Bridge CPU */ if ((cur_cpu_family == 6) && (cur_cpu_model == 0x2A || cur_cpu_model == 0x2D)) rc = 1; } fclose(fd); return rc; }
/*! \brief process_vex_range() is used to read the vex_ranges for RPM/LOAD allocate the memory for storing the data and call the needed functions to read the values into the arrays. \see read_number_from_line \param vex (Vex_Import *) pointer to the Vex_Import structure \param arg (ImportParserArg) enumeration to decide which range we are going to read \param string (gchar *) Line of text passed to parse. \param iochannel (GIOChannel *) Pointer to iochannel representing VEXfile for retrieving additional data. \returns status of the operation (G_IO_STATUS_ERROR/G_IO_STATUS_NORMAL) */ G_MODULE_EXPORT GIOStatus process_vex_range(Vex_Import *vex, ImportParserArg arg, gchar * string, GIOChannel *iochannel) { GIOStatus status = G_IO_STATUS_ERROR; gint i = 0; gint value = 0; gint num_bins = 0; gchar ** str_array = NULL; gchar * result = NULL; if (!string) { dbg_func_f(CRITICAL,g_strdup(__FILE__": process_vex_range()\n\t String passed was NULL\n")); return G_IO_STATUS_ERROR; } str_array = g_strsplit(string, "[", 2); result = g_strdup(str_array[1]); g_strfreev(str_array); str_array = g_strsplit(result, "]", 2); result = g_strdup(str_array[0]); num_bins = atoi(result); /* Allocate memory for array of values... :) */ switch(arg) { case VEX_RPM_RANGE: vex->total_x_bins = num_bins; vex->x_bins = g_new0(gint, num_bins); vex->got_rpm = TRUE; break; case VEX_LOAD_RANGE: vex->total_y_bins = num_bins; vex->y_bins = g_new0(gint, num_bins); vex->got_load = TRUE; break; default: break; } for (i=0; i<num_bins; i++) { status = read_number_from_line(&value,iochannel); if (status != G_IO_STATUS_NORMAL) { update_logbar_f("tools_view","warning",_("VEX Import: File I/O Read problem, file may be incomplete <---ERROR\n"),FALSE,FALSE,FALSE); break; } switch (arg) { case VEX_RPM_RANGE: vex->x_bins[i] = value; break; case VEX_LOAD_RANGE: vex->y_bins[i] = value; break; default: break; } } if (status == G_IO_STATUS_NORMAL) { if (arg == VEX_RPM_RANGE) update_logbar_f("tools_view",NULL,_("VEX Import: RPM bins loaded successfully \n"),FALSE,FALSE,FALSE); if (arg == VEX_LOAD_RANGE) update_logbar_f("tools_view",NULL,_("VEX Import: LOAD bins loaded successfully \n"),FALSE,FALSE,FALSE); } return status; }