Browse Source

Add -r option to enable HT

Serj Kalichev 10 years ago
parent
commit
bbeceb6558
3 changed files with 12 additions and 5 deletions
  1. 9 2
      birq.c
  2. 1 1
      cpu.h
  3. 2 2
      cpu_parse.c

+ 9 - 2
birq.c

@@ -54,6 +54,7 @@ struct options {
 	int log_facility;
 	float threshold;
 	int verbose;
+	int ht;
 };
 
 /*--------------------------------------------------------- */
@@ -123,7 +124,7 @@ int main(int argc, char **argv)
 
 	/* Scan CPUs */
 	cpus = lub_list_new(cpu_list_compare);
-	scan_cpus(cpus);
+	scan_cpus(cpus, opts->ht);
 
 	/* Prepare data structures */
 	irqs = lub_list_new(irq_list_compare);
@@ -221,6 +222,7 @@ static struct options *opts_init(void)
 	opts->log_facility = LOG_DAEMON;
 	opts->threshold = BIRQ_DEFAULT_THRESHOLD;
 	opts->verbose = 0;
+	opts->ht = 0;
 
 	return opts;
 }
@@ -238,7 +240,7 @@ static void opts_free(struct options *opts)
 /* Parse command line options */
 static int opts_parse(int argc, char *argv[], struct options *opts)
 {
-	static const char *shortopts = "hvp:dO:t:i";
+	static const char *shortopts = "hvp:dO:t:ir";
 #ifdef HAVE_GETOPT_H
 	static const struct option longopts[] = {
 		{"help",	0, NULL, 'h'},
@@ -248,6 +250,7 @@ static int opts_parse(int argc, char *argv[], struct options *opts)
 		{"facility",	1, NULL, 'O'},
 		{"threshold",	1, NULL, 't'},
 		{"verbose",	0, NULL, 'i'},
+		{"ht",		0, NULL, 'r'},
 		{NULL,		0, NULL, 0}
 	};
 #endif
@@ -273,6 +276,9 @@ static int opts_parse(int argc, char *argv[], struct options *opts)
 		case 'i':
 			opts->verbose = 1;
 			break;
+		case 'r':
+			opts->ht = 1;
+			break;
 		case 'O':
 			if (lub_log_facility(optarg, &(opts->log_facility))) {
 				fprintf(stderr, "Error: Illegal syslog facility %s.\n", optarg);
@@ -341,6 +347,7 @@ static void help(int status, const char *argv0)
 		printf("\t-h, --help\tPrint this help.\n");
 		printf("\t-d, --debug\tDebug mode. Don't daemonize.\n");
 		printf("\t-i, --verbose\tBe verbose.\n");
+		printf("\t-r, --ht\tEnable hyper-threading. Not recommended.\n");
 		printf("\t-p <path>, --pid=<path>\tFile to save daemon's PID to.\n");
 		printf("\t-O, --facility\tSyslog facility. Default is DAEMON.\n");
 		printf("\t-t <float>, --threshold=<float>\tThreshold to consider CPU is overloaded, in percents.\n");

+ 1 - 1
cpu.h

@@ -25,7 +25,7 @@ int cpu_list_compare_len(const void *first, const void *second);
 
 /* CPU list functions */
 int cpu_list_free(lub_list_t *cpus);
-int scan_cpus(lub_list_t *cpus);
+int scan_cpus(lub_list_t *cpus, int ht);
 int show_cpus(lub_list_t *cpus);
 cpu_t * cpu_list_search(lub_list_t *cpus, unsigned int id);
 

+ 2 - 2
cpu_parse.c

@@ -141,7 +141,7 @@ int show_cpus(lub_list_t *cpus)
 }
 
 /* Search for CPUs */
-int scan_cpus(lub_list_t *cpus)
+int scan_cpus(lub_list_t *cpus, int ht)
 {
 	FILE *fd;
 	char path[PATH_MAX];
@@ -178,7 +178,7 @@ int scan_cpus(lub_list_t *cpus)
 		fclose(fd);
 
 		/* Don't use second thread of Hyper Threading */
-		if (cpu_list_search_ht(cpus, package_id, core_id))
+		if (!ht && cpu_list_search_ht(cpus, package_id, core_id))
 			continue;
 
 		new = cpu_new(id);