Browse Source

Merge branch 'rename_thr' into bfgminer

Conflicts:
	configure.ac
Luke Dashjr 13 years ago
parent
commit
a0ed5ce3b8
7 changed files with 48 additions and 0 deletions
  1. 4 0
      api.c
  2. 1 0
      configure.ac
  3. 1 0
      driver-opencl.c
  4. 2 0
      findnonce.c
  5. 16 0
      miner.c
  6. 1 0
      miner.h
  7. 23 0
      util.c

+ 4 - 0
api.c

@@ -3028,6 +3028,8 @@ popipo:
 
 static void *quit_thread(__maybe_unused void *userdata)
 {
+	rename_thr("bfg-rpc-quit");
+
 	// allow thread creator to finish whatever it's doing
 	mutex_lock(&quit_restart_lock);
 	mutex_unlock(&quit_restart_lock);
@@ -3042,6 +3044,8 @@ static void *quit_thread(__maybe_unused void *userdata)
 
 static void *restart_thread(__maybe_unused void *userdata)
 {
+	rename_thr("bfg-rpc-restart");
+
 	// allow thread creator to finish whatever it's doing
 	mutex_lock(&quit_restart_lock);
 	mutex_unlock(&quit_restart_lock);

+ 1 - 0
configure.ac

@@ -58,6 +58,7 @@ dnl Checks for header files.
 AC_HEADER_STDC
 AC_CHECK_HEADERS(syslog.h)
 AC_CHECK_HEADERS([sys/epoll.h])
+AC_CHECK_HEADERS([sys/prctl.h])
 
 AC_FUNC_ALLOCA
 

+ 1 - 0
driver-opencl.c

@@ -1358,6 +1358,7 @@ void *reinit_gpu(void *userdata)
 	int gpu;
 
 	pthread_detach(pthread_self());
+	rename_thr("bfg-reinit_gpu");
 
 select_cgpu:
 	cgpu = tq_pop(mythr->q, NULL);

+ 2 - 0
findnonce.c

@@ -17,6 +17,7 @@
 #include <string.h>
 
 #include "findnonce.h"
+#include "miner.h"
 #include "scrypt.h"
 
 const uint32_t SHA256_K[64] = {
@@ -241,6 +242,7 @@ static void *postcalc_hash(void *userdata)
 	int entry = 0, nonces = 0;
 
 	pthread_detach(pthread_self());
+	rename_thr("bfg-postcalchsh");
 
 	for (entry = 0; entry < FOUND; entry++) {
 		uint32_t nonce = pcd->res[entry];

+ 16 - 0
miner.c

@@ -2449,6 +2449,7 @@ static void *get_work_thread(void *userdata)
 	int failures = 0;
 
 	pthread_detach(pthread_self());
+	rename_thr("bfg-get_work");
 
 	applog(LOG_DEBUG, "Creating extra get work thread");
 
@@ -2629,6 +2630,7 @@ static void *submit_work_thread(void *userdata)
 	time_t staleexpire;
 
 	pthread_detach(pthread_self());
+	rename_thr("bfg-submit_work");
 
 	applog(LOG_DEBUG, "Creating extra submit work thread");
 
@@ -3107,6 +3109,7 @@ static void *stage_thread(void *userdata)
 	struct thr_info *mythr = userdata;
 	bool ok = true;
 
+	rename_thr("bfg-stage");
 	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
 
 	while (ok) {
@@ -3779,6 +3782,7 @@ retry:
 
 static void *input_thread(void __maybe_unused *userdata)
 {
+	rename_thr("bfg-input");
 	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
 
 	if (!curses_active)
@@ -3841,6 +3845,7 @@ static void *workio_thread(void *userdata)
 	struct thr_info *mythr = userdata;
 	bool ok = true;
 
+	rename_thr("bfg-workio");
 	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
 
 	while (ok) {
@@ -3895,6 +3900,7 @@ static void *api_thread(void *userdata)
 	struct thr_info *mythr = userdata;
 
 	pthread_detach(pthread_self());
+	rename_thr("bfg-rpc");
 	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
 
 	api(api_thr_id);
@@ -4543,6 +4549,12 @@ void *miner_thread(void *userdata)
 	struct cgminer_stats *pool_stats;
 	struct timeval getwork_start;
 
+	{
+		char thrname[16];
+		sprintf(thrname, "bfg-miner-%s%d", api->name, cgpu->device_id);
+		rename_thr(thrname);
+	}
+
 	/* Try to cycle approximately 5 times before each log update */
 	const long cycle = opt_log_interval / 5 ? : 1;
 	struct timeval tv_start, tv_end, tv_workstart, tv_lastupdate;
@@ -4828,6 +4840,8 @@ static void *longpoll_thread(void *userdata)
 	int failures = 0;
 	int rolltime;
 
+	rename_thr("bfg-longpoll");
+
 	curl = curl_easy_init();
 	if (unlikely(!curl)) {
 		applog(LOG_ERR, "CURL initialisation failed");
@@ -4984,6 +4998,7 @@ static void reap_curl(struct pool *pool)
 
 static void *watchpool_thread(void __maybe_unused *userdata)
 {
+	rename_thr("bfg-watchpool");
 	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
 
 	while (42) {
@@ -5050,6 +5065,7 @@ static void *watchdog_thread(void __maybe_unused *userdata)
 	const unsigned int interval = WATCHDOG_INTERVAL;
 	struct timeval zero_tv;
 
+	rename_thr("bfg-watchdog");
 	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
 
 	memset(&zero_tv, 0, sizeof(struct timeval));

+ 1 - 0
miner.h

@@ -464,6 +464,7 @@ extern int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*s
 extern void thr_info_cancel(struct thr_info *thr);
 extern void thr_info_freeze(struct thr_info *thr);
 extern void nmsleep(unsigned int msecs);
+extern void rename_thr(const char* name);
 
 struct string_elist {
 	char *string;

+ 23 - 0
util.c

@@ -1,6 +1,8 @@
 /*
  * Copyright 2011-2012 Con Kolivas
  * Copyright 2010 Jeff Garzik
+ * Copyright 2012 Giel van Schijndel
+ * Copyright 2012 Gavin Andresen
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the Free
@@ -16,12 +18,19 @@
 #include <ctype.h>
 #include <stdarg.h>
 #include <string.h>
+#include <pthread.h>
 #include <jansson.h>
 #include <curl/curl.h>
 #include <time.h>
 #include <errno.h>
 #include <unistd.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_PRCTL_H
+# include <sys/prctl.h>
+#endif
+#if defined(__FreeBSD__) || defined(__OpenBSD__)
+# include <pthread_np.h>
+#endif
 #ifndef WIN32
 # include <sys/socket.h>
 # include <netinet/in.h>
@@ -709,3 +718,17 @@ void nmsleep(unsigned int msecs)
 		ret = nanosleep(&twait, &tleft);
 	} while (ret == -1 && errno == EINTR);
 }
+
+void rename_thr(const char* name) {
+#if defined(PR_SET_NAME)
+	// Only the first 15 characters are used (16 - NUL terminator)
+	prctl(PR_SET_NAME, name, 0, 0, 0);
+#elif defined(__APPLE__)
+	pthread_setname_np(name);
+#elif defined(__FreeBSD__) || defined(__OpenBSD__)
+	pthread_set_name_np(pthread_self(), name);
+#else
+	// Prevent warnings for unused parameters...
+	(void)name;
+#endif
+}