Browse Source

Merge branch 'tui_manage_dev' into bfgminer

Luke Dashjr 12 years ago
parent
commit
c4c06166a2
4 changed files with 260 additions and 232 deletions
  1. 8 19
      README
  2. 116 197
      driver-opencl.c
  3. 132 16
      miner.c
  4. 4 0
      miner.h

+ 8 - 19
README

@@ -322,7 +322,14 @@ WHILE RUNNING:
 
 The following options are available while running with a single keypress:
 
-[P]ool management [G]PU management [S]ettings [D]isplay options [Q]uit
+[M]anage devices [P]ool management [S]ettings [D]isplay options [Q]uit
+
+M gives you something like:
+
+Select processor to manage using up/down arrow keys
+ ICA 0 :                | 212.4/340.6/448.7Mh/s | A:4 R:0+0(none) HW:0/none
+[E]nable [D]isable
+
 
 P gives you:
 
@@ -359,24 +366,6 @@ co[M]pact: off
 Q quits the application.
 
 
-G gives you something like:
-
-GPU 0: [124.2 / 191.3 Mh/s] [A:77  R:33+0( 42%)  HW:0]
-Temp: 67.0 C
-Fan Speed: 35% (2500 RPM)
-Engine Clock: 960 MHz
-Memory Clock: 480 MHz
-Vddc: 1.200 V
-Activity: 93%
-Powertune: 0%
-Last initialised: [2011-09-06 12:03:56]
-Thread 0: 62.4 Mh/s Enabled ALIVE
-Thread 1: 60.2 Mh/s Enabled ALIVE
-
-[E]nable [D]isable [R]estart GPU [C]hange settings
-Or press any other key to continue
-
-
 The running log shows output like this:
 
  [2013-02-13 00:26:30] Accepted 1758e8df BFL 0  pool 0 Diff 10/1

+ 116 - 197
driver-opencl.c

@@ -835,217 +835,131 @@ struct device_drv opencl_api;
 #endif /* HAVE_OPENCL */
 
 #if defined(HAVE_OPENCL) && defined(HAVE_CURSES)
-void manage_gpu(void)
+static
+void opencl_wlogprint_status(struct cgpu_info *cgpu)
 {
 	struct thr_info *thr;
-	int selected, gpu, i;
+	int i;
 	char checkin[40];
-	char input;
-
-	if (!opt_g_threads)
-		return;
-
-	opt_loginput = true;
-	immedok(logwin, true);
-	clear_logwin();
-retry:
-
-	for (gpu = 0; gpu < nDevs; gpu++) {
-		struct cgpu_info *cgpu = &gpus[gpu];
-		double displayed_rolling, displayed_total;
-		bool mhash_base = true;
-
-		displayed_rolling = cgpu->rolling;
-		displayed_total = cgpu->total_mhashes / cgpu_runtime(cgpu);
-		if (displayed_rolling < 1) {
-			displayed_rolling *= 1000;
-			displayed_total *= 1000;
-			mhash_base = false;
-		}
-
-		wlog("%"PRIpreprv": %.1f / %.1f %sh/s | A:%d  R:%d  HW:%d  U:%.2f/m  I:%d\n",
-			cgpu->proc_repr,
-			displayed_rolling, displayed_total, mhash_base ? "M" : "K",
-			cgpu->accepted, cgpu->rejected, cgpu->hw_errors,
-			cgpu->utility, cgpu->intensity);
+	double displayed_rolling;
+	bool mhash_base = !(cgpu->rolling < 1);
+	char logline[255];
+	strcpy(logline, ""); // In case it has no data
+	
+	tailsprintf(logline, "I:%s%d  ", (cgpu->dynamic ? "d" : ""), cgpu->intensity);
 #ifdef HAVE_ADL
-		if (gpus[gpu].has_adl) {
-			int engineclock = 0, memclock = 0, activity = 0, fanspeed = 0, fanpercent = 0, powertune = 0;
-			float temp = 0, vddc = 0;
-
-			if (gpu_stats(gpu, &temp, &engineclock, &memclock, &vddc, &activity, &fanspeed, &fanpercent, &powertune)) {
-				char logline[255];
-
-				strcpy(logline, ""); // In case it has no data
-				if (temp != -1)
-					sprintf(logline, "%.1f C  ", temp);
-				if (fanspeed != -1 || fanpercent != -1) {
-					tailsprintf(logline, "F: ");
-					if (fanpercent != -1)
-						tailsprintf(logline, "%d%% ", fanpercent);
-					if (fanspeed != -1)
-						tailsprintf(logline, "(%d RPM) ", fanspeed);
-					tailsprintf(logline, " ");
-				}
-				if (engineclock != -1)
-					tailsprintf(logline, "E: %d MHz  ", engineclock);
-				if (memclock != -1)
-					tailsprintf(logline, "M: %d MHz  ", memclock);
-				if (vddc != -1)
-					tailsprintf(logline, "V: %.3fV  ", vddc);
-				if (activity != -1)
-					tailsprintf(logline, "A: %d%%  ", activity);
-				if (powertune != -1)
-					tailsprintf(logline, "P: %d%%", powertune);
-				tailsprintf(logline, "\n");
-				_wlog(logline);
-			}
+	if (cgpu->has_adl) {
+		int engineclock = 0, memclock = 0, activity = 0, fanspeed = 0, fanpercent = 0, powertune = 0;
+		float temp = 0, vddc = 0;
+
+		if (gpu_stats(cgpu->device_id, &temp, &engineclock, &memclock, &vddc, &activity, &fanspeed, &fanpercent, &powertune)) {
+			if (engineclock != -1)
+				tailsprintf(logline, "E: %d MHz  ", engineclock);
+			if (memclock != -1)
+				tailsprintf(logline, "M: %d MHz  ", memclock);
+			if (vddc != -1)
+				tailsprintf(logline, "V: %.3fV  ", vddc);
+			if (activity != -1)
+				tailsprintf(logline, "A: %d%%  ", activity);
+			if (powertune != -1)
+				tailsprintf(logline, "P: %d%%", powertune);
 		}
+	}
 #endif
-		wlog("Last initialised: %s\n", cgpu->init);
-		wlog("Intensity: ");
-		if (gpus[gpu].dynamic)
-			wlog("Dynamic (only one thread in use)\n");
-		else
-			wlog("%d\n", gpus[gpu].intensity);
-		for (i = 0; i < mining_threads; i++) {
-			thr = get_thread(i);
-			if (thr->cgpu != cgpu)
-				continue;
-			get_datestamp(checkin, &thr->last);
-			displayed_rolling = thr->rolling;
-			if (!mhash_base)
-				displayed_rolling *= 1000;
-			wlog("Thread %d: %.1f %sh/s %s ", i, displayed_rolling, mhash_base ? "M" : "K" , cgpu->deven != DEV_DISABLED ? "Enabled" : "Disabled");
-			switch (cgpu->status) {
-				default:
-				case LIFE_WELL:
-					wlog("ALIVE");
-					break;
-				case LIFE_SICK:
-					wlog("SICK reported in %s", checkin);
-					break;
-				case LIFE_DEAD:
-					wlog("DEAD reported in %s", checkin);
-					break;
-				case LIFE_INIT:
-				case LIFE_NOSTART:
-					wlog("Never started");
-					break;
-			}
-			if (thr->pause)
-				wlog(" paused");
-			wlog("\n");
+	
+	wlogprint("%s\n", logline);
+	
+	wlogprint("Last initialised: %s\n", cgpu->init);
+	
+	for (i = 0; i < mining_threads; i++) {
+		thr = get_thread(i);
+		if (thr->cgpu != cgpu)
+			continue;
+		
+		get_datestamp(checkin, &thr->last);
+		displayed_rolling = thr->rolling;
+		if (!mhash_base)
+			displayed_rolling *= 1000;
+		sprintf(logline, "Thread %d: %.1f %sh/s %s ", i, displayed_rolling, mhash_base ? "M" : "K" , cgpu->deven != DEV_DISABLED ? "Enabled" : "Disabled");
+		switch (cgpu->status) {
+			default:
+			case LIFE_WELL:
+				tailsprintf(logline, "ALIVE");
+				break;
+			case LIFE_SICK:
+				tailsprintf(logline, "SICK reported in %s", checkin);
+				break;
+			case LIFE_DEAD:
+				tailsprintf(logline, "DEAD reported in %s", checkin);
+				break;
+			case LIFE_INIT:
+			case LIFE_NOSTART:
+				tailsprintf(logline, "Never started");
+				break;
 		}
-		wlog("\n");
+		if (thr->pause)
+			tailsprintf(logline, " paused");
+		wlogprint("%s\n", logline);
 	}
+}
 
-	wlogprint("[E]nable [D]isable [I]ntensity [R]estart GPU %s\n",adl_active ? "[C]hange settings" : "");
-
-	wlogprint("Or press any other key to continue\n");
-	logwin_update();
-	input = getch();
-
-	if (nDevs == 1)
-		selected = 0;
-	else
-		selected = -1;
-	if (!strncasecmp(&input, "e", 1)) {
-		struct cgpu_info *cgpu;
+static
+void opencl_tui_wlogprint_choices(struct cgpu_info *cgpu)
+{
+	wlogprint("[I]ntensity [R]estart GPU ");
+	if (cgpu->has_adl)
+		wlogprint("[C]hange settings ");
+}
 
-		if (selected)
-			selected = curses_int("Select GPU to enable");
-		if (selected < 0 || selected >= nDevs) {
-			wlogprint("Invalid selection\n");
-			goto retry;
-		}
-		cgpu = &gpus[selected];
-		if (gpus[selected].deven != DEV_DISABLED) {
-			wlogprint("Device already enabled\n");
-			goto retry;
-		}
-		gpus[selected].deven = DEV_ENABLED;
-		if (cgpu->status != LIFE_WELL) {
-			wlogprint("Must restart device before enabling it");
-			goto retry;
-		}
-		proc_enable(cgpu);
-		goto retry;
-	} if (!strncasecmp(&input, "d", 1)) {
-		if (selected)
-			selected = curses_int("Select GPU to disable");
-		if (selected < 0 || selected >= nDevs) {
-			wlogprint("Invalid selection\n");
-			goto retry;
-		}
-		if (gpus[selected].deven == DEV_DISABLED) {
-			wlogprint("Device already disabled\n");
-			goto retry;
-		}
-		gpus[selected].deven = DEV_DISABLED;
-		goto retry;
-	} else if (!strncasecmp(&input, "i", 1)) {
-		int intensity;
-		char *intvar;
-
-		if (selected)
-			selected = curses_int("Select GPU to change intensity on");
-		if (selected < 0 || selected >= nDevs) {
-			wlogprint("Invalid selection\n");
-			goto retry;
-		}
-		intvar = curses_input("Set GPU scan intensity (d or " _MIN_INTENSITY_STR " -> " _MAX_INTENSITY_STR ")");
-		if (!intvar) {
-			wlogprint("Invalid input\n");
-			goto retry;
-		}
-		if (!strncasecmp(intvar, "d", 1)) {
-			wlogprint("Dynamic mode enabled on gpu %d\n", selected);
-			gpus[selected].dynamic = true;
-			pause_dynamic_threads(selected);
+static
+const char *opencl_tui_handle_choice(struct cgpu_info *cgpu, int input)
+{
+	switch (input)
+	{
+		case 'i': case 'I':
+		{
+			int intensity;
+			char *intvar;
+
+			intvar = curses_input("Set GPU scan intensity (d or " _MIN_INTENSITY_STR " -> " _MAX_INTENSITY_STR ")");
+			if (!intvar)
+				return "Invalid intensity\n";
+			if (!strncasecmp(intvar, "d", 1)) {
+				cgpu->dynamic = true;
+				pause_dynamic_threads(cgpu->device_id);
+				free(intvar);
+				return "Dynamic mode enabled\n";
+			}
+			intensity = atoi(intvar);
 			free(intvar);
-			goto retry;
-		}
-		intensity = atoi(intvar);
-		free(intvar);
-		if (intensity < MIN_INTENSITY || intensity > MAX_INTENSITY) {
-			wlogprint("Invalid selection\n");
-			goto retry;
+			if (intensity < MIN_INTENSITY || intensity > MAX_INTENSITY)
+				return "Invalid intensity (out of range)\n";
+			cgpu->dynamic = false;
+			cgpu->intensity = intensity;
+			pause_dynamic_threads(cgpu->device_id);
+			return "Intensity changed\n";
 		}
-		gpus[selected].dynamic = false;
-		gpus[selected].intensity = intensity;
-		wlogprint("Intensity on gpu %d set to %d\n", selected, intensity);
-		pause_dynamic_threads(selected);
-		goto retry;
-	} else if (!strncasecmp(&input, "r", 1)) {
-		if (selected)
-			selected = curses_int("Select GPU to attempt to restart");
-		if (selected < 0 || selected >= nDevs) {
-			wlogprint("Invalid selection\n");
-			goto retry;
-		}
-		wlogprint("Attempting to restart threads of GPU %d\n", selected);
-		reinit_device(&gpus[selected]);
-		goto retry;
-	} else if (adl_active && (!strncasecmp(&input, "c", 1))) {
-		if (selected)
-			selected = curses_int("Select GPU to change settings on");
-		if (selected < 0 || selected >= nDevs) {
-			wlogprint("Invalid selection\n");
-			goto retry;
+		case 'r': case 'R':
+			reinit_device(cgpu);
+			return "Attempting to restart\n";
+		case 'c': case 'C':
+		{
+			char logline[256];
+			
+			clear_logwin();
+			get_statline3(logline, cgpu, true, true);
+			wattron(logwin, A_BOLD);
+			waddstr(logwin, logline);
+			wattroff(logwin, A_BOLD);
+			wlogprint("\n");
+			
+			change_gpusettings(cgpu->device_id);
+			return "";  // Force refresh
 		}
-		change_gpusettings(selected);
-		goto retry;
-	} else
-		clear_logwin();
-
-	immedok(logwin, false);
-	opt_loginput = false;
-}
-#else
-void manage_gpu(void)
-{
+	}
+	return NULL;
 }
+
 #endif
 
 
@@ -1847,6 +1761,11 @@ struct device_drv opencl_api = {
 	.drv_detect = opencl_detect,
 	.reinit_device = reinit_opencl_device,
 	.get_statline_before = get_opencl_statline_before,
+#ifdef HAVE_CURSES
+	.proc_wlogprint_status = opencl_wlogprint_status,
+	.proc_tui_wlogprint_choices = opencl_tui_wlogprint_choices,
+	.proc_tui_handle_choice = opencl_tui_handle_choice,
+#endif
 	.get_api_extra_device_status = get_opencl_api_extra_device_status,
 	.thread_prepare = opencl_thread_prepare,
 	.thread_init = opencl_thread_init,

+ 132 - 16
miner.c

@@ -278,6 +278,11 @@ const
 #endif
 bool curses_active;
 
+#ifdef HAVE_CURSES
+bool selecting_device;
+unsigned selected_device;
+#endif
+
 static char current_block[40];
 
 /* Protected by ch_lock */
@@ -2395,7 +2400,7 @@ percentf2(double p, double t, char *buf)
 static void adj_width(int var, int *length);
 #endif
 
-static void get_statline2(char *buf, struct cgpu_info *cgpu, bool for_curses)
+void get_statline3(char *buf, struct cgpu_info *cgpu, bool for_curses, bool opt_show_procs)
 {
 #ifdef HAVE_CURSES
 	static int awidth = 1, rwidth = 1, swidth = 1, hwwidth = 1;
@@ -2567,7 +2572,8 @@ static void get_statline2(char *buf, struct cgpu_info *cgpu, bool for_curses)
 	}
 }
 
-#define get_statline(buf, cgpu)  get_statline2(buf, cgpu, false)
+#define get_statline(buf, cgpu)               get_statline3(buf, cgpu, false, opt_show_procs)
+#define get_statline2(buf, cgpu, for_curses)  get_statline3(buf, cgpu, for_curses, opt_show_procs)
 
 static void text_print_status(int thr_id)
 {
@@ -2645,8 +2651,7 @@ static void curses_print_status(void)
 		  current_hash, block_diff, net_hashrate, blocktime);
 	mvwhline(statuswin, 6, 0, '-', 80);
 	mvwhline(statuswin, statusy - 1, 0, '-', 80);
-	mvwprintw(statuswin, devcursor - 1, 1, "[P]ool management %s[S]ettings [D]isplay options [Q]uit",
-		have_opencl ? "[G]PU management " : "");
+	mvwprintw(statuswin, devcursor - 1, 1, "[M]anage devices [P]ool management [S]ettings [D]isplay options [Q]uit");
 }
 
 static void adj_width(int var, int *length)
@@ -2685,10 +2690,26 @@ static void curses_print_devstatus(struct cgpu_info *cgpu)
 		return;
 	
 	get_statline2(logline, cgpu, true);
+	if (selecting_device && (opt_show_procs ? (selected_device == cgpu->cgminer_id) : (devices[selected_device]->device == cgpu)))
+		wattron(statuswin, A_REVERSE);
 	waddstr(statuswin, logline);
+	wattroff(statuswin, A_REVERSE);
 
 	wclrtoeol(statuswin);
 }
+
+static
+void refresh_devstatus() {
+	if (curses_active_locked()) {
+		int i;
+		for (i = 0; i < total_devices; i++)
+			curses_print_devstatus(get_devices(i));
+		touchwin(statuswin);
+		wrefresh(statuswin);
+		unlock_curses();
+	}
+}
+
 #endif
 
 static void print_status(int thr_id)
@@ -5912,6 +5933,109 @@ retry:
 	opt_loginput = false;
 }
 
+void manage_device(void)
+{
+	char logline[256];
+	const char *msg = NULL;
+	struct cgpu_info *cgpu;
+	const struct device_drv *drv;
+	
+	opt_loginput = true;
+	selecting_device = true;
+	immedok(logwin, true);
+	
+devchange:
+	cgpu = devices[selected_device];
+	drv = cgpu->drv;
+	refresh_devstatus();
+	
+refresh:
+	clear_logwin();
+	wlogprint("Select processor to manage using up/down arrow keys\n");
+	
+	get_statline3(logline, cgpu, true, true);
+	wattron(logwin, A_BOLD);
+	waddstr(logwin, logline);
+	wattroff(logwin, A_BOLD);
+	wlogprint("\n");
+	
+	if (drv->proc_wlogprint_status && likely(cgpu->status != LIFE_INIT))
+		drv->proc_wlogprint_status(cgpu);
+	
+	wlogprint("\n");
+	// TODO: Last share at TIMESTAMP on pool N
+	// TODO: Custom device info/commands
+	if (cgpu->deven != DEV_ENABLED)
+		wlogprint("[E]nable ");
+	if (cgpu->deven != DEV_DISABLED)
+		wlogprint("[D]isable ");
+	if (drv->proc_tui_wlogprint_choices && likely(cgpu->status != LIFE_INIT))
+		drv->proc_tui_wlogprint_choices(cgpu);
+	wlogprint("\n");
+	wlogprint("Or press Enter when done\n");
+	if (msg)
+	{
+		wattron(logwin, A_BOLD);
+		waddstr(logwin, msg);
+		wattroff(logwin, A_BOLD);
+		msg = NULL;
+	}
+	logwin_update();
+	
+	while (true)
+	{
+		int input = getch();
+		switch (input) {
+			case 'd': case 'D':
+				if (cgpu->deven == DEV_DISABLED)
+					msg = "Processor already disabled\n";
+				else
+				{
+					cgpu->deven = DEV_DISABLED;
+					msg = "Processor being disabled\n";
+				}
+				goto refresh;
+			case 'e': case 'E':
+				if (cgpu->deven == DEV_ENABLED)
+					msg = "Processor already enabled\n";
+				else
+				{
+					proc_enable(cgpu);
+					msg = "Processor being enabled\n";
+				}
+				goto refresh;
+			case KEY_DOWN:
+				if (selected_device >= total_devices - 1)
+					break;
+				++selected_device;
+				goto devchange;
+			case KEY_UP:
+				if (selected_device <= 0)
+					break;
+				--selected_device;
+				goto devchange;
+			case 'Q': case 'q':
+			case KEY_BREAK: case KEY_BACKSPACE: case KEY_CANCEL: case KEY_CLOSE: case KEY_EXIT:
+			case '\x1b':  // ESC
+			case '\n':
+				goto out;
+			default:
+				if (drv->proc_tui_handle_choice && likely(cgpu->status != LIFE_INIT))
+				{
+					msg = drv->proc_tui_handle_choice(cgpu, input);
+					if (msg)
+						goto refresh;
+				}
+		}
+	}
+
+out:
+	selecting_device = false;
+	clear_logwin();
+	immedok(logwin, false);
+	opt_loginput = false;
+}
+
 static void *input_thread(void __maybe_unused *userdata)
 {
 	RenameThread("input");
@@ -5930,16 +6054,15 @@ static void *input_thread(void __maybe_unused *userdata)
 		case 'd': case 'D':
 			display_options();
 			break;
+		case 'm': case 'M':
+			manage_device();
+			break;
 		case 'p': case 'P':
 			display_pools();
 			break;
 		case 's': case 'S':
 			set_options();
 			break;
-		case 'g': case 'G':
-			if (have_opencl)
-				manage_gpu();
-			break;
 #ifdef HAVE_CURSES
 		case KEY_DOWN:
 			if (devsummaryYOffset < -(total_lines + devcursor - statusy))
@@ -5949,14 +6072,7 @@ static void *input_thread(void __maybe_unused *userdata)
 			if (devsummaryYOffset == 0)
 				break;
 			++devsummaryYOffset;
-			if (curses_active_locked()) {
-				int i;
-				for (i = 0; i < total_devices; i++)
-					curses_print_devstatus(get_devices(i));
-				touchwin(statuswin);
-				wrefresh(statuswin);
-				unlock_curses();
-			}
+			refresh_devstatus();
 			break;
 #endif
 		}

+ 4 - 0
miner.h

@@ -297,6 +297,9 @@ struct device_drv {
 	bool (*get_stats)(struct cgpu_info *);
 	bool (*identify_device)(struct cgpu_info *);  // e.g. to flash a led
 	char *(*set_device)(struct cgpu_info *, char *option, char *setting, char *replybuf);
+	void (*proc_wlogprint_status)(struct cgpu_info *);
+	void (*proc_tui_wlogprint_choices)(struct cgpu_info *);
+	const char *(*proc_tui_handle_choice)(struct cgpu_info *, int input);
 
 	// Thread-specific functions
 	bool (*thread_prepare)(struct thr_info *);
@@ -1264,6 +1267,7 @@ extern struct work *find_queued_work_bymidstate(struct cgpu_info *cgpu, char *mi
 extern void work_completed(struct cgpu_info *cgpu, struct work *work);
 extern bool abandon_work(struct work *, struct timeval *work_runtime, uint64_t hashes);
 extern void hash_queued_work(struct thr_info *mythr);
+extern void get_statline3(char *buf, struct cgpu_info *, bool for_curses, bool opt_show_procs);
 extern void tailsprintf(char *f, const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 2, 3);
 extern void _wlog(const char *str);
 extern void _wlogprint(const char *str);