Browse Source

Abstract add_cgpu function, to handle device id numbering and devices array

nfactor-troky
Luke Dashjr 13 years ago
parent
commit
303dbf4664
  1. 25
      cgminer.c
  2. 6
      driver-bitforce.c
  3. 5
      driver-cpu.c
  4. 3
      driver-icarus.c
  5. 3
      driver-opencl.c
  6. 2
      miner.h

25
cgminer.c

@ -4263,6 +4263,31 @@ void enable_device(struct cgpu_info *cgpu) @@ -4263,6 +4263,31 @@ void enable_device(struct cgpu_info *cgpu)
#endif
}
struct _cgpu_devid_counter {
char name[4];
int lastid;
UT_hash_handle hh;
};
bool add_cgpu(struct cgpu_info*cgpu)
{
static struct _cgpu_devid_counter *devids = NULL;
struct _cgpu_devid_counter *d;
HASH_FIND_STR(devids, cgpu->api->name, d);
if (d)
cgpu->device_id = ++d->lastid;
else
{
d = malloc(sizeof(*d));
memcpy(d->name, cgpu->api->name, sizeof(d->name));
cgpu->device_id = d->lastid = 0;
HASH_ADD_STR(devids, name, d);
}
devices[total_devices++] = cgpu;
return true;
}
int main (int argc, char *argv[])
{
struct block *block, *tmpblock;

6
driver-bitforce.c

@ -92,7 +92,6 @@ static void BFwrite(int fd, const void *buf, ssize_t bufLen) @@ -92,7 +92,6 @@ static void BFwrite(int fd, const void *buf, ssize_t bufLen)
static bool bitforce_detect_one(const char *devpath)
{
char pdevbuf[0x100];
static int i = 0;
if (total_devices == MAX_DEVICES)
return false;
@ -117,14 +116,11 @@ static bool bitforce_detect_one(const char *devpath) @@ -117,14 +116,11 @@ static bool bitforce_detect_one(const char *devpath)
// We have a real BitForce!
struct cgpu_info *bitforce;
bitforce = calloc(1, sizeof(*bitforce));
devices[total_devices++] = bitforce;
bitforce->api = &bitforce_api;
bitforce->device_id = i++;
bitforce->device_path = strdup(devpath);
bitforce->deven = DEV_ENABLED;
bitforce->threads = 1;
return true;
return add_cgpu(bitforce);
}
static bool bitforce_detect_auto_udev()

5
driver-cpu.c

@ -739,13 +739,12 @@ static void cpu_detect() @@ -739,13 +739,12 @@ static void cpu_detect()
for (i = 0; i < opt_n_threads; ++i) {
struct cgpu_info *cgpu;
cgpu = devices[total_devices + i] = &cpus[i];
cgpu = &cpus[i];
cgpu->api = &cpu_api;
cgpu->deven = DEV_ENABLED;
cgpu->device_id = i;
cgpu->threads = 1;
add_cgpu(cgpu);
}
total_devices += opt_n_threads;
}
static void reinit_cpu_device(struct cgpu_info *cpu)

3
driver-icarus.c

@ -191,10 +191,9 @@ static bool icarus_detect_one(const char *devpath) @@ -191,10 +191,9 @@ static bool icarus_detect_one(const char *devpath)
struct cgpu_info *icarus;
icarus = calloc(1, sizeof(struct cgpu_info));
icarus->api = &icarus_api;
icarus->device_id = total_devices;
icarus->device_path = strdup(devpath);
icarus->threads = 1;
devices[total_devices++] = icarus;
add_cgpu(icarus);
applog(LOG_INFO, "Found Icarus at %s, mark as %d",
devpath, icarus->device_id);

3
driver-opencl.c

@ -1093,12 +1093,13 @@ static void opencl_detect() @@ -1093,12 +1093,13 @@ static void opencl_detect()
for (i = 0; i < nDevs; ++i) {
struct cgpu_info *cgpu;
cgpu = devices[total_devices++] = &gpus[i];
cgpu = &gpus[i];
cgpu->deven = DEV_ENABLED;
cgpu->api = &opencl_api;
cgpu->device_id = i;
cgpu->threads = opt_g_threads;
cgpu->virtual_gpu = i;
add_cgpu(cgpu);
}
if (!opt_noadl)

2
miner.h

@ -275,6 +275,8 @@ struct cgpu_info { @@ -275,6 +275,8 @@ struct cgpu_info {
time_t last_share_pool_time;
};
extern bool add_cgpu(struct cgpu_info*);
struct thread_q {
struct list_head q;

Loading…
Cancel
Save