Browse Source

now we have dynamic get_work_count

Xiangfu 13 years ago
parent
commit
9f8ab773f3
3 changed files with 23 additions and 12 deletions
  1. 16 8
      cgminer.c
  2. 4 3
      driver-avalon.c
  3. 3 1
      driver-avalon.h

+ 16 - 8
cgminer.c

@@ -5349,7 +5349,15 @@ void *miner_thread(void *userdata)
 	uint32_t max_nonce = api->can_limit_work ? api->can_limit_work(mythr) : 0xffffffff;
 	uint32_t max_nonce = api->can_limit_work ? api->can_limit_work(mythr) : 0xffffffff;
 	int64_t hashes_done = 0;
 	int64_t hashes_done = 0;
 	int64_t hashes;
 	int64_t hashes;
-#ifndef USE_AVALON
+#ifdef USE_AVALON
+	struct avalon_info *info = avalon_info[cgpu->device_id];
+	int i;
+	int avalon_get_work_count = info->miner_count;
+	struct work **work = calloc(1,
+				    avalon_get_work_count * sizeof(struct work *));
+	if (!work)
+		quit(1, "Faile on Avalon calloc");
+#else
 	struct work *work;
 	struct work *work;
 #endif
 #endif
 	const bool primary = (!mythr->device_thread) || mythr->primary_thread;
 	const bool primary = (!mythr->device_thread) || mythr->primary_thread;
@@ -5377,10 +5385,7 @@ void *miner_thread(void *userdata)
 	while (1) {
 	while (1) {
 		mythr->work_restart = false;
 		mythr->work_restart = false;
 #ifdef USE_AVALON
 #ifdef USE_AVALON
-		int i;
-		struct work *work[AVALON_GET_WORK_COUNT];
-
-		for (i = 0; i < AVALON_GET_WORK_COUNT; i++) {
+		for (i = 0; i < avalon_get_work_count; i++) {
 			work[i] = get_work(mythr, thr_id);
 			work[i] = get_work(mythr, thr_id);
 			work[i]->blk.nonce = 0;
 			work[i]->blk.nonce = 0;
 		}
 		}
@@ -5391,7 +5396,7 @@ void *miner_thread(void *userdata)
 		cgpu->new_work = true;
 		cgpu->new_work = true;
 		cgpu->max_hashes = 0;
 		cgpu->max_hashes = 0;
 		gettimeofday(&tv_workstart, NULL);
 		gettimeofday(&tv_workstart, NULL);
-		for (i = 0; i < AVALON_GET_WORK_COUNT; i++) {
+		for (i = 0; i < avalon_get_work_count; i++) {
 			if (api->prepare_work && !api->prepare_work(mythr, work[i])) {
 			if (api->prepare_work && !api->prepare_work(mythr, work[i])) {
 				applog(LOG_ERR, "work prepare failed, exiting "
 				applog(LOG_ERR, "work prepare failed, exiting "
 				       "mining thread %d", thr_id);
 				       "mining thread %d", thr_id);
@@ -5417,12 +5422,12 @@ void *miner_thread(void *userdata)
 			dev_stats->getwork_calls++;
 			dev_stats->getwork_calls++;
 
 
 #ifdef USE_AVALON
 #ifdef USE_AVALON
-			for (i = 0; i < AVALON_GET_WORK_COUNT; i++) {
+			for (i = 0; i < avalon_get_work_count; i++) {
 				pool_stats = &(work[i]->pool->cgminer_stats);
 				pool_stats = &(work[i]->pool->cgminer_stats);
 #else
 #else
 			pool_stats = &(work->pool->cgminer_stats);
 			pool_stats = &(work->pool->cgminer_stats);
 #endif
 #endif
-			/* FIXME: should be check all works */
+				/* FIXME: should be check all works */
 				timeradd(&getwork_start,
 				timeradd(&getwork_start,
 					 &(pool_stats->getwork_wait),
 					 &(pool_stats->getwork_wait),
 					 &(pool_stats->getwork_wait));
 					 &(pool_stats->getwork_wait));
@@ -5526,6 +5531,9 @@ void *miner_thread(void *userdata)
 	}
 	}
 
 
 out:
 out:
+#ifdef USE_AVALON
+	free(work);
+#endif
 	if (api->thread_shutdown)
 	if (api->thread_shutdown)
 		api->thread_shutdown(mythr);
 		api->thread_shutdown(mythr);
 
 

+ 4 - 3
driver-avalon.c

@@ -37,7 +37,7 @@
 
 
 static int option_offset = -1;
 static int option_offset = -1;
 
 
-static struct avalon_info **avalon_info;
+struct avalon_info **avalon_info;
 struct device_api avalon_api;
 struct device_api avalon_api;
 static int avalon_init_task(struct thr_info *thr, struct avalon_task *at,
 static int avalon_init_task(struct thr_info *thr, struct avalon_task *at,
 			    uint8_t reset, uint8_t ff, uint8_t fan,
 			    uint8_t reset, uint8_t ff, uint8_t fan,
@@ -296,6 +296,7 @@ static void do_avalon_close(struct thr_info *thr)
 	struct cgpu_info *avalon = thr->cgpu;
 	struct cgpu_info *avalon = thr->cgpu;
 	avalon_close(avalon->device_fd);
 	avalon_close(avalon->device_fd);
 	avalon->device_fd = -1;
 	avalon->device_fd = -1;
+	/* FIXME: we should free the bulk0/1/2 */
 }
 }
 
 
 static void set_timing_mode(struct cgpu_info *avalon)
 static void set_timing_mode(struct cgpu_info *avalon)
@@ -408,13 +409,13 @@ static void get_options(int this_option_offset, int *baud, int *miner_count,
 
 
 			if (colon3 && *colon3) {
 			if (colon3 && *colon3) {
 				tmp = atoi(colon3);
 				tmp = atoi(colon3);
-				if (tmp > 0 && tmp <= AVALON_DEFAULT_TIMEOUT)
+				if (tmp > 0 && tmp <= 0xff)
 					*timeout = tmp;
 					*timeout = tmp;
 				else {
 				else {
 					sprintf(err_buf,
 					sprintf(err_buf,
 						"Invalid avalon-options for "
 						"Invalid avalon-options for "
 						"timeout (%s) must be 1 ~ %d",
 						"timeout (%s) must be 1 ~ %d",
-						colon3, AVALON_DEFAULT_TIMEOUT);
+						colon3, 0xff);
 					quit(1, err_buf);
 					quit(1, err_buf);
 				}
 				}
 
 

+ 3 - 1
driver-avalon.h

@@ -61,7 +61,7 @@ struct avalon_info {
 
 
 #define AVALON_GET_WORK_COUNT 3 // 24
 #define AVALON_GET_WORK_COUNT 3 // 24
 #define AVALON_DEFAULT_FAN_PWM 0x98
 #define AVALON_DEFAULT_FAN_PWM 0x98
-#define AVALON_DEFAULT_TIMEOUT 0xff //0x32
+#define AVALON_DEFAULT_TIMEOUT 0x32
 #define AVALON_DEFAULT_MINER_NUM 24
 #define AVALON_DEFAULT_MINER_NUM 24
 #define AVALON_DEFAULT_ASIC_NUM 0xA
 #define AVALON_DEFAULT_ASIC_NUM 0xA
 
 
@@ -91,6 +91,8 @@ struct avalon_info {
 #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
 #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
 ASSERT1(sizeof(uint32_t) == 4);
 ASSERT1(sizeof(uint32_t) == 4);
 
 
+extern  struct avalon_info **avalon_info;
+
 static inline uint8_t rev8(uint8_t d)
 static inline uint8_t rev8(uint8_t d)
 {
 {
     int i;
     int i;