Browse Source

Merge commit 'd8de1bb' into bfgminer

Luke Dashjr 13 years ago
parent
commit
ad40d1d3fb
8 changed files with 64 additions and 93 deletions
  1. 1 4
      api.c
  2. 0 2
      driver-cpu.c
  3. 6 6
      driver-icarus.c
  4. 23 24
      driver-opencl.c
  5. 0 2
      driver-ztex.c
  6. 19 31
      fpgautils.c
  7. 8 16
      miner.c
  8. 7 8
      miner.h

+ 1 - 4
api.c

@@ -1611,10 +1611,7 @@ static void addpool(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
 		return;
 		return;
 	}
 	}
 
 
-	if (add_pool_details(true, url, user, pass) == ADD_POOL_MAXIMUM) {
-		strcpy(io_buffer, message(MSG_TOOMANYP, MAX_POOLS, NULL, isjson));
-		return;
-	}
+	add_pool_details(true, url, user, pass);
 
 
 	ptr = escape_string(url, isjson);
 	ptr = escape_string(url, isjson);
 	strcpy(io_buffer, message(MSG_ADDPOOL, 0, ptr, isjson));
 	strcpy(io_buffer, message(MSG_ADDPOOL, 0, ptr, isjson));

+ 0 - 2
driver-cpu.c

@@ -735,8 +735,6 @@ static void cpu_detect()
 	if (num_processors < 1)
 	if (num_processors < 1)
 		return;
 		return;
 
 
-	if (total_devices + opt_n_threads > MAX_DEVICES)
-		opt_n_threads = MAX_DEVICES - total_devices;
 	cpus = calloc(opt_n_threads, sizeof(struct cgpu_info));
 	cpus = calloc(opt_n_threads, sizeof(struct cgpu_info));
 	if (unlikely(!cpus))
 	if (unlikely(!cpus))
 		quit(1, "Failed to calloc cpus");
 		quit(1, "Failed to calloc cpus");

+ 6 - 6
driver-icarus.c

@@ -181,7 +181,7 @@ struct ICARUS_INFO {
 };
 };
 
 
 // One for each possible device
 // One for each possible device
-static struct ICARUS_INFO *icarus_info[MAX_DEVICES];
+static struct ICARUS_INFO **icarus_info;
 
 
 struct device_api icarus_api;
 struct device_api icarus_api;
 
 
@@ -467,15 +467,15 @@ static bool icarus_detect_one(const char *devpath)
 	icarus->device_path = strdup(devpath);
 	icarus->device_path = strdup(devpath);
 	icarus->threads = 1;
 	icarus->threads = 1;
 	add_cgpu(icarus);
 	add_cgpu(icarus);
+	icarus_info = realloc(icarus_info, sizeof(struct ICARUS_INFO *) * (total_devices + 1));
 
 
 	applog(LOG_INFO, "Found Icarus at %s, mark as %d",
 	applog(LOG_INFO, "Found Icarus at %s, mark as %d",
 		devpath, icarus->device_id);
 		devpath, icarus->device_id);
 
 
-	if (icarus_info[icarus->device_id] == NULL) {
-		icarus_info[icarus->device_id] = (struct ICARUS_INFO *)malloc(sizeof(struct ICARUS_INFO));
-		if (unlikely(!(icarus_info[icarus->device_id])))
-			quit(1, "Failed to malloc ICARUS_INFO");
-	}
+	// Since we are adding a new device on the end it needs to always be allocated
+	icarus_info[icarus->device_id] = (struct ICARUS_INFO *)malloc(sizeof(struct ICARUS_INFO));
+	if (unlikely(!(icarus_info[icarus->device_id])))
+		quit(1, "Failed to malloc ICARUS_INFO");
 
 
 	info = icarus_info[icarus->device_id];
 	info = icarus_info[icarus->device_id];
 
 

+ 23 - 24
driver-opencl.c

@@ -1349,9 +1349,6 @@ static void opencl_detect()
 		nDevs = 0;
 		nDevs = 0;
 	}
 	}
 
 
-	if (MAX_DEVICES - total_devices < nDevs)
-		nDevs = MAX_DEVICES - total_devices;
-
 	if (!nDevs)
 	if (!nDevs)
 		return;
 		return;
 
 
@@ -1600,37 +1597,37 @@ static uint64_t opencl_scanhash(struct thr_info *thr, struct work *work,
 	struct cgpu_info *gpu = thr->cgpu;
 	struct cgpu_info *gpu = thr->cgpu;
 	_clState *clState = clStates[thr_id];
 	_clState *clState = clStates[thr_id];
 	const cl_kernel *kernel = &clState->kernel;
 	const cl_kernel *kernel = &clState->kernel;
+	const int dynamic_us = opt_dynamic_interval * 1000;
 
 
-	double gpu_ms_average = 7;
 	cl_int status;
 	cl_int status;
-
 	size_t globalThreads[1];
 	size_t globalThreads[1];
 	size_t localThreads[1] = { clState->wsize };
 	size_t localThreads[1] = { clState->wsize };
 	unsigned int threads;
 	unsigned int threads;
 	unsigned int hashes;
 	unsigned int hashes;
 
 
-
-	struct timeval tv_gpustart, tv_gpuend, diff;
-	suseconds_t gpu_us;
-
-	gettimeofday(&tv_gpustart, NULL);
-	timeval_subtract(&diff, &tv_gpustart, &tv_gpuend);
 	/* This finish flushes the readbuffer set with CL_FALSE later */
 	/* This finish flushes the readbuffer set with CL_FALSE later */
 	clFinish(clState->commandQueue);
 	clFinish(clState->commandQueue);
-	gettimeofday(&tv_gpuend, NULL);
-	timeval_subtract(&diff, &tv_gpuend, &tv_gpustart);
-	gpu_us = diff.tv_sec * 1000000 + diff.tv_usec;
-	decay_time(&gpu_ms_average, gpu_us / 1000);
+	gettimeofday(&gpu->tv_gpuend, NULL);
+
 	if (gpu->dynamic) {
 	if (gpu->dynamic) {
-		/* Try to not let the GPU be out for longer than 6ms, but
-		 * increase intensity when the system is idle, unless
-		 * dynamic is disabled. */
-		if (gpu_ms_average > opt_dynamic_interval) {
-			if (gpu->intensity > MIN_INTENSITY)
-				--gpu->intensity;
-		} else if (gpu_ms_average < ((opt_dynamic_interval / 2) ? : 1)) {
-			if (gpu->intensity < MAX_INTENSITY)
-				++gpu->intensity;
+		struct timeval diff;
+		suseconds_t gpu_us;
+
+		timersub(&gpu->tv_gpuend, &gpu->tv_gpustart, &diff);
+		gpu_us = diff.tv_sec * 1000 + diff.tv_usec;
+		if (likely(gpu_us > 0)) {
+			gpu->gpu_us_average = (gpu->gpu_us_average + gpu_us * 0.63) / 1.63;
+
+			/* Try to not let the GPU be out for longer than 
+			 * opt_dynamic_interval in ms, but increase
+			 * intensity when the system is idle in dynamic mode */
+			if (gpu->gpu_us_average > dynamic_us) {
+				if (gpu->intensity > MIN_INTENSITY)
+					--gpu->intensity;
+			} else if (gpu->gpu_us_average < dynamic_us / 2) {
+				if (gpu->intensity < MAX_INTENSITY)
+					++gpu->intensity;
+			}
 		}
 		}
 	}
 	}
 	set_threads_hashes(clState->vwidth, &threads, &hashes, globalThreads,
 	set_threads_hashes(clState->vwidth, &threads, &hashes, globalThreads,
@@ -1664,6 +1661,8 @@ static uint64_t opencl_scanhash(struct thr_info *thr, struct work *work,
 		clFinish(clState->commandQueue);
 		clFinish(clState->commandQueue);
 	}
 	}
 
 
+	gettimeofday(&gpu->tv_gpustart, NULL);
+
 	if (clState->goffset) {
 	if (clState->goffset) {
 		size_t global_work_offset[1];
 		size_t global_work_offset[1];
 
 

+ 0 - 2
driver-ztex.c

@@ -66,8 +66,6 @@ static void ztex_detect(void)
 	applog(LOG_WARNING, "Found %d ztex board(s)", cnt);
 	applog(LOG_WARNING, "Found %d ztex board(s)", cnt);
 
 
 	for (i = 0; i < cnt; i++) {
 	for (i = 0; i < cnt; i++) {
-		if (total_devices == MAX_DEVICES)
-			break;
 		ztex = calloc(1, sizeof(struct cgpu_info));
 		ztex = calloc(1, sizeof(struct cgpu_info));
 		ztex->api = &ztex_api;
 		ztex->api = &ztex_api;
 		ztex->device_ztex = ztex_devices[i]->dev;
 		ztex->device_ztex = ztex_devices[i]->dev;

+ 19 - 31
fpgautils.c

@@ -40,9 +40,6 @@
 char
 char
 serial_autodetect_udev(detectone_func_t detectone, const char*prodname)
 serial_autodetect_udev(detectone_func_t detectone, const char*prodname)
 {
 {
-	if (total_devices == MAX_DEVICES)
-		return 0;
-
 	struct udev *udev = udev_new();
 	struct udev *udev = udev_new();
 	struct udev_enumerate *enumerate = udev_enumerate_new(udev);
 	struct udev_enumerate *enumerate = udev_enumerate_new(udev);
 	struct udev_list_entry *list_entry;
 	struct udev_list_entry *list_entry;
@@ -64,9 +61,6 @@ serial_autodetect_udev(detectone_func_t detectone, const char*prodname)
 			++found;
 			++found;
 
 
 		udev_device_unref(device);
 		udev_device_unref(device);
-
-		if (total_devices == MAX_DEVICES)
-			break;
 	}
 	}
 	udev_enumerate_unref(enumerate);
 	udev_enumerate_unref(enumerate);
 	udev_unref(udev);
 	udev_unref(udev);
@@ -85,9 +79,6 @@ char
 serial_autodetect_devserial(detectone_func_t detectone, const char*prodname)
 serial_autodetect_devserial(detectone_func_t detectone, const char*prodname)
 {
 {
 #ifndef WIN32
 #ifndef WIN32
-	if (total_devices == MAX_DEVICES)
-		return 0;
-
 	DIR *D;
 	DIR *D;
 	struct dirent *de;
 	struct dirent *de;
 	const char udevdir[] = "/dev/serial/by-id";
 	const char udevdir[] = "/dev/serial/by-id";
@@ -104,11 +95,8 @@ serial_autodetect_devserial(detectone_func_t detectone, const char*prodname)
 		if (!strstr(de->d_name, prodname))
 		if (!strstr(de->d_name, prodname))
 			continue;
 			continue;
 		strcpy(devfile, de->d_name);
 		strcpy(devfile, de->d_name);
-		if (detectone(devpath)) {
+		if (detectone(devpath))
 			++found;
 			++found;
-			if (total_devices == MAX_DEVICES)
-				break;
-		}
 	}
 	}
 	closedir(D);
 	closedir(D);
 
 
@@ -121,9 +109,6 @@ serial_autodetect_devserial(detectone_func_t detectone, const char*prodname)
 char
 char
 _serial_detect(const char*dname, detectone_func_t detectone, autoscan_func_t autoscan, bool forceauto)
 _serial_detect(const char*dname, detectone_func_t detectone, autoscan_func_t autoscan, bool forceauto)
 {
 {
-	if (total_devices == MAX_DEVICES)
-		return 0;
-
 	struct string_elist *iter, *tmp;
 	struct string_elist *iter, *tmp;
 	const char*s, *p;
 	const char*s, *p;
 	bool inhibitauto = false;
 	bool inhibitauto = false;
@@ -148,12 +133,10 @@ _serial_detect(const char*dname, detectone_func_t detectone, autoscan_func_t aut
 			string_elist_del(iter);
 			string_elist_del(iter);
 			inhibitauto = true;
 			inhibitauto = true;
 			++found;
 			++found;
-			if (total_devices == MAX_DEVICES)
-				break;
 		}
 		}
 	}
 	}
 
 
-	if ((forceauto || !inhibitauto) && autoscan && total_devices < MAX_DEVICES)
+	if ((forceauto || !inhibitauto) && autoscan)
 		found += autoscan();
 		found += autoscan();
 
 
 	return found;
 	return found;
@@ -198,28 +181,33 @@ serial_open(const char*devpath, unsigned long baud, signed short timeout, bool p
 	if (unlikely(fdDev == -1))
 	if (unlikely(fdDev == -1))
 		return -1;
 		return -1;
 
 
-	struct termios pattr;
-	tcgetattr(fdDev, &pattr);
-	pattr.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
-	pattr.c_oflag &= ~OPOST;
-	pattr.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
-	pattr.c_cflag &= ~(CSIZE | PARENB);
-	pattr.c_cflag |= CS8;
+	struct termios my_termios;
+
+	tcgetattr(fdDev, &my_termios);
 
 
 	switch (baud) {
 	switch (baud) {
 	case 0: break;
 	case 0: break;
-	case 115200: pattr.c_cflag = B115200; break;
+	case 115200: my_termios.c_cflag = B115200; break;
 	default:
 	default:
 		applog(LOG_WARNING, "Unrecognized baud rate: %lu", baud);
 		applog(LOG_WARNING, "Unrecognized baud rate: %lu", baud);
 	}
 	}
-	pattr.c_cflag |= CREAD | CLOCAL;
+
+	my_termios.c_cflag |= CS8;
+	my_termios.c_cflag |= CREAD;
+	my_termios.c_cflag |= CLOCAL;
+	my_termios.c_cflag &= ~(CSIZE | PARENB);
+
+	my_termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK |
+				ISTRIP | INLCR | IGNCR | ICRNL | IXON);
+	my_termios.c_oflag &= ~OPOST;
+	my_termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
 
 
 	if (timeout >= 0) {
 	if (timeout >= 0) {
-		pattr.c_cc[VTIME] = (cc_t)timeout;
-		pattr.c_cc[VMIN] = 0;
+		my_termios.c_cc[VTIME] = (cc_t)timeout;
+		my_termios.c_cc[VMIN] = 0;
 	}
 	}
 
 
-	tcsetattr(fdDev, TCSANOW, &pattr);
+	tcsetattr(fdDev, TCSANOW, &my_termios);
 	if (purge)
 	if (purge)
 		tcflush(fdDev, TCIOFLUSH);
 		tcflush(fdDev, TCIOFLUSH);
 	return fdDev;
 	return fdDev;

+ 8 - 16
miner.c

@@ -117,7 +117,7 @@ struct list_head scan_devices;
 static signed int devices_enabled;
 static signed int devices_enabled;
 static bool opt_removedisabled;
 static bool opt_removedisabled;
 int total_devices;
 int total_devices;
-struct cgpu_info *devices[MAX_DEVICES];
+struct cgpu_info **devices;
 bool have_opencl;
 bool have_opencl;
 int opt_n_threads = -1;
 int opt_n_threads = -1;
 int mining_threads;
 int mining_threads;
@@ -189,7 +189,7 @@ unsigned int found_blocks;
 unsigned int local_work;
 unsigned int local_work;
 unsigned int total_go, total_ro;
 unsigned int total_go, total_ro;
 
 
-struct pool *pools[MAX_POOLS];
+struct pool **pools;
 static struct pool *currentpool = NULL;
 static struct pool *currentpool = NULL;
 
 
 int total_pools;
 int total_pools;
@@ -394,6 +394,7 @@ static struct pool *add_pool(void)
 	if (!pool)
 	if (!pool)
 		quit(1, "Failed to malloc pool in add_pool");
 		quit(1, "Failed to malloc pool in add_pool");
 	pool->pool_no = pool->prio = total_pools;
 	pool->pool_no = pool->prio = total_pools;
+	pools = realloc(pools, sizeof(struct pool *) * (total_pools + 2));
 	pools[total_pools++] = pool;
 	pools[total_pools++] = pool;
 	if (unlikely(pthread_mutex_init(&pool->pool_lock, NULL)))
 	if (unlikely(pthread_mutex_init(&pool->pool_lock, NULL)))
 		quit(1, "Failed to pthread_mutex_init in add_pool");
 		quit(1, "Failed to pthread_mutex_init in add_pool");
@@ -2190,7 +2191,7 @@ static bool stale_work(struct work *work, bool share)
 	pool = work->pool;
 	pool = work->pool;
 	/* Factor in the average getwork delay of this pool, rounding it up to
 	/* Factor in the average getwork delay of this pool, rounding it up to
 	 * the nearest second */
 	 * the nearest second */
-	getwork_delay = pool->cgminer_pool_stats.getwork_wait_rolling * 5 + 1;
+	getwork_delay = (pool->cgminer_pool_stats.getwork_wait_rolling + 1) * 5;
 	if (!share) {
 	if (!share) {
 		work_expiry -= getwork_delay;
 		work_expiry -= getwork_delay;
 		if (unlikely(work_expiry < 5))
 		if (unlikely(work_expiry < 5))
@@ -4774,13 +4775,10 @@ char *curses_input(const char *query)
 }
 }
 #endif
 #endif
 
 
-int add_pool_details(bool live, char *url, char *user, char *pass)
+void add_pool_details(bool live, char *url, char *user, char *pass)
 {
 {
 	struct pool *pool;
 	struct pool *pool;
 
 
-	if (total_pools == MAX_POOLS)
-		return ADD_POOL_MAXIMUM;
-
 	pool = add_pool();
 	pool = add_pool();
 
 
 	pool->rpc_url = url;
 	pool->rpc_url = url;
@@ -4796,8 +4794,6 @@ int add_pool_details(bool live, char *url, char *user, char *pass)
 	pool->enabled = POOL_ENABLED;
 	pool->enabled = POOL_ENABLED;
 	if (live && !pool_active(pool, false))
 	if (live && !pool_active(pool, false))
 		pool->idle = true;
 		pool->idle = true;
-
-	return ADD_POOL_OK;
 }
 }
 
 
 #ifdef HAVE_CURSES
 #ifdef HAVE_CURSES
@@ -4807,10 +4803,6 @@ static bool input_pool(bool live)
 	bool ret = false;
 	bool ret = false;
 
 
 	immedok(logwin, true);
 	immedok(logwin, true);
-	if (total_pools == MAX_POOLS) {
-		wlogprint("Reached maximum number of pools.\n");
-		goto out;
-	}
 	wlogprint("Input server details.\n");
 	wlogprint("Input server details.\n");
 
 
 	url = curses_input("URL");
 	url = curses_input("URL");
@@ -4838,7 +4830,8 @@ static bool input_pool(bool live)
 	if (!pass)
 	if (!pass)
 		goto out;
 		goto out;
 
 
-	ret = (add_pool_details(live, url, user, pass) == ADD_POOL_OK);
+	add_pool_details(live, url, user, pass);
+	ret = true;
 out:
 out:
 	immedok(logwin, false);
 	immedok(logwin, false);
 
 
@@ -5008,6 +5001,7 @@ bool add_cgpu(struct cgpu_info*cgpu)
 		cgpu->device_id = d->lastid = 0;
 		cgpu->device_id = d->lastid = 0;
 		HASH_ADD_STR(devids, name, d);
 		HASH_ADD_STR(devids, name, d);
 	}
 	}
+	devices = realloc(devices, sizeof(struct cgpu_info *) * (total_devices + 2));
 	devices[total_devices++] = cgpu;
 	devices[total_devices++] = cgpu;
 	return true;
 	return true;
 }
 }
@@ -5099,8 +5093,6 @@ int main(int argc, char *argv[])
 		gpus[i].dynamic = true;
 		gpus[i].dynamic = true;
 #endif
 #endif
 
 
-	memset(devices, 0, sizeof(devices));
-
 	/* parse command line */
 	/* parse command line */
 	opt_register_table(opt_config_table,
 	opt_register_table(opt_config_table,
 			   "Options for both config file and command line");
 			   "Options for both config file and command line");

+ 7 - 8
miner.h

@@ -340,6 +340,10 @@ struct cgpu_info {
 	cl_uint vwidth;
 	cl_uint vwidth;
 	size_t work_size;
 	size_t work_size;
 	enum cl_kernels kernel;
 	enum cl_kernels kernel;
+
+	struct timeval tv_gpustart;;
+	struct timeval tv_gpuend;
+	double gpu_us_average;
 #endif
 #endif
 
 
 	float temp;
 	float temp;
@@ -572,14 +576,9 @@ extern void api(int thr_id);
 
 
 extern struct pool *current_pool(void);
 extern struct pool *current_pool(void);
 extern int active_pools(void);
 extern int active_pools(void);
-extern int add_pool_details(bool live, char *url, char *user, char *pass);
-
-#define ADD_POOL_MAXIMUM 1
-#define ADD_POOL_OK 0
+extern void add_pool_details(bool live, char *url, char *user, char *pass);
 
 
 #define MAX_GPUDEVICES 16
 #define MAX_GPUDEVICES 16
-#define MAX_DEVICES 64
-#define MAX_POOLS (32)
 
 
 #define MIN_INTENSITY -10
 #define MIN_INTENSITY -10
 #define _MIN_INTENSITY_STR "-10"
 #define _MIN_INTENSITY_STR "-10"
@@ -599,9 +598,9 @@ extern double total_secs;
 extern int mining_threads;
 extern int mining_threads;
 extern struct cgpu_info *cpus;
 extern struct cgpu_info *cpus;
 extern int total_devices;
 extern int total_devices;
-extern struct cgpu_info *devices[];
+extern struct cgpu_info **devices;
 extern int total_pools;
 extern int total_pools;
-extern struct pool *pools[MAX_POOLS];
+extern struct pool **pools;
 extern const char *algo_names[];
 extern const char *algo_names[];
 extern enum sha256_algos opt_algo;
 extern enum sha256_algos opt_algo;
 extern struct strategies strategies[];
 extern struct strategies strategies[];