1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-22 12:34:27 +00:00

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

This commit is contained in:
Luke Dashjr 2012-03-18 20:09:03 -04:00
parent e131dfab31
commit 303dbf4664
6 changed files with 33 additions and 11 deletions

View File

@ -4263,6 +4263,31 @@ void enable_device(struct cgpu_info *cgpu)
#endif #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[]) int main (int argc, char *argv[])
{ {
struct block *block, *tmpblock; struct block *block, *tmpblock;

View File

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

View File

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

View File

@ -191,10 +191,9 @@ static bool icarus_detect_one(const char *devpath)
struct cgpu_info *icarus; struct cgpu_info *icarus;
icarus = calloc(1, sizeof(struct cgpu_info)); icarus = calloc(1, sizeof(struct cgpu_info));
icarus->api = &icarus_api; icarus->api = &icarus_api;
icarus->device_id = total_devices;
icarus->device_path = strdup(devpath); icarus->device_path = strdup(devpath);
icarus->threads = 1; icarus->threads = 1;
devices[total_devices++] = icarus; add_cgpu(icarus);
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);

View File

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

View File

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