Browse Source

api.c data structure - tested + updated get_api_stats/driver-icarus.c

nfactor-troky
Kano 13 years ago
parent
commit
d8abfb713e
  1. 84
      api.c
  2. 22
      driver-icarus.c
  3. 3
      miner.h

84
api.c

@ -631,6 +631,35 @@ static char *escape_string(char *str, bool isjson)
return buf; return buf;
} }
static struct api_data *api_add_extra(struct api_data *root, struct api_data *extra)
{
struct api_data *tmp;
if (root)
{
if (extra) {
// extra tail
tmp = extra->prev;
// extra prev = root tail
extra->prev = root->prev;
// root tail next = extra
root->prev->next = extra;
// extra tail next = root
tmp->next = root;
// root prev = extra tail
root->prev = tmp;
}
}
else
root = extra;
return root;
}
static struct api_data *api_add_data_full(struct api_data *root, char *name, enum api_data_type type, void *data, bool copy_data) static struct api_data *api_add_data_full(struct api_data *root, char *name, enum api_data_type type, void *data, bool copy_data)
{ {
struct api_data *api_data; struct api_data *api_data;
@ -2669,33 +2698,36 @@ void dosave(__maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unuse
ptr = NULL; ptr = NULL;
} }
static int itemstats(int i, char *id, struct cgminer_stats *stats, struct cgminer_pool_stats *pool_stats, char *extra, bool isjson) static int itemstats(int i, char *id, struct cgminer_stats *stats, struct cgminer_pool_stats *pool_stats, struct api_data *extra, bool isjson)
{ {
struct api_data *root = NULL; struct api_data *root = NULL;
char buf[TMPBUFSIZ]; char buf[TMPBUFSIZ];
/*
if (stats->getwork_calls || (extra != NULL && *extra)) { if (stats->getwork_calls || (extra != NULL && *extra)) {
if (extra == NULL) if (extra == NULL)
extra = (char *)BLANK; extra = (char *)BLANK;
*/
root = api_add_int(root, "STATS", &i, false); root = api_add_int(root, "STATS", &i, false);
root = api_add_string(root, "ID", id, false); root = api_add_string(root, "ID", id, false);
root = api_add_double(root, "Elapsed", &(total_secs), false); root = api_add_double(root, "Elapsed", &(total_secs), false);
root = api_add_uint32(root, "Calls", &(stats->getwork_calls), false); root = api_add_uint32(root, "Calls", &(stats->getwork_calls), false);
root = api_add_timeval(root, "Wait", &(stats->getwork_wait), false); root = api_add_timeval(root, "Wait", &(stats->getwork_wait), false);
root = api_add_timeval(root, "Max", &(stats->getwork_wait_max), false); root = api_add_timeval(root, "Max", &(stats->getwork_wait_max), false);
root = api_add_timeval(root, "Min", &(stats->getwork_wait_min), false); root = api_add_timeval(root, "Min", &(stats->getwork_wait_min), false);
if (pool_stats) { if (pool_stats) {
root = api_add_uint32(root, "Pool Calls", &(pool_stats->getwork_calls), false); root = api_add_uint32(root, "Pool Calls", &(pool_stats->getwork_calls), false);
root = api_add_uint32(root, "Pool Attempts", &(pool_stats->getwork_attempts), false); root = api_add_uint32(root, "Pool Attempts", &(pool_stats->getwork_attempts), false);
root = api_add_timeval(root, "Pool Wait", &(pool_stats->getwork_wait), false); root = api_add_timeval(root, "Pool Wait", &(pool_stats->getwork_wait), false);
root = api_add_timeval(root, "Pool Max", &(pool_stats->getwork_wait_max), false); root = api_add_timeval(root, "Pool Max", &(pool_stats->getwork_wait_max), false);
root = api_add_timeval(root, "Pool Min", &(pool_stats->getwork_wait_min), false); root = api_add_timeval(root, "Pool Min", &(pool_stats->getwork_wait_min), false);
root = api_add_double(root, "Pool Av", &(pool_stats->getwork_wait_rolling), false); root = api_add_double(root, "Pool Av", &(pool_stats->getwork_wait_rolling), false);
} }
// TODO: zzzz handle extra <- rewrite the api interface if (extra)
root = api_add_extra(root, extra);
/* /*
sprintf(buf, isjson sprintf(buf, isjson
@ -2729,21 +2761,21 @@ static int itemstats(int i, char *id, struct cgminer_stats *stats, struct cgmine
strcat(io_buffer, buf); strcat(io_buffer, buf);
*/ */
if (isjson && (i > 0)) if (isjson && (i > 0))
strcat(io_buffer, COMMA); strcat(io_buffer, COMMA);
root = print_data(root, buf, isjson); root = print_data(root, buf, isjson);
strcat(io_buffer, buf); strcat(io_buffer, buf);
i++; i++;
} // }
return i; return i;
} }
static void minerstats(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, bool isjson, __maybe_unused char group) static void minerstats(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, bool isjson, __maybe_unused char group)
{ {
char extra[TMPBUFSIZ]; struct api_data *extra;
char id[20]; char id[20];
int i, j; int i, j;
@ -2760,9 +2792,9 @@ static void minerstats(__maybe_unused SOCKETTYPE c, __maybe_unused char *param,
if (cgpu && cgpu->api) { if (cgpu && cgpu->api) {
if (cgpu->api->get_api_stats) if (cgpu->api->get_api_stats)
cgpu->api->get_api_stats(extra, cgpu, isjson); extra = cgpu->api->get_api_stats(cgpu);
else else
extra[0] = '\0'; extra = NULL;
sprintf(id, "%s%d", cgpu->api->name, cgpu->device_id); sprintf(id, "%s%d", cgpu->api->name, cgpu->device_id);
i = itemstats(i, id, &(cgpu->cgminer_stats), NULL, extra, isjson); i = itemstats(i, id, &(cgpu->cgminer_stats), NULL, extra, isjson);

22
driver-icarus.c

@ -676,13 +676,30 @@ static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work,
return hash_count; return hash_count;
} }
static void icarus_api_stats(char *buf, struct cgpu_info *cgpu, bool isjson) //static void icarus_api_stats(char *buf, struct cgpu_info *cgpu, bool isjson)
static struct api_data *icarus_api_stats(struct cgpu_info *cgpu)
{ {
struct api_data *root = NULL;
struct ICARUS_INFO *info = icarus_info[cgpu->device_id]; struct ICARUS_INFO *info = icarus_info[cgpu->device_id];
// Warning, access to these is not locked - but we don't really // Warning, access to these is not locked - but we don't really
// care since hashing performance is way more important than // care since hashing performance is way more important than
// locking access to displaying API debug 'stats' // locking access to displaying API debug 'stats'
// If locking becomes an issue for any of them, use copy_data=true also
root = api_add_int(root, "read_count", &(info->read_count), false);
root = api_add_double(root, "fullnonce", &(info->fullnonce), false);
root = api_add_int(root, "count", &(info->count), false);
root = api_add_hs(root, "Hs", &(info->Hs), false);
root = api_add_double(root, "W", &(info->W), false);
root = api_add_uint(root, "total_values", &(info->values), false);
root = api_add_uint64(root, "range", &(info->hash_count_range), false);
root = api_add_uint64(root, "history_count", &(info->history_count), false);
root = api_add_timeval(root, "history_time", &(info->history_time), false);
root = api_add_uint(root, "min_data_count", &(info->min_data_count), false);
root = api_add_uint(root, "timing_values", &(info->history[0].values), false);
root = api_add_const(root, "timing_mode", timing_mode_str(info->timing_mode), false);
root = api_add_bool(root, "is_timing", &(info->do_icarus_timing), false);
/*
sprintf(buf, isjson sprintf(buf, isjson
? "\"read_count\":%d,\"fullnonce\":%f,\"count\":%d,\"Hs\":%.15f,\"W\":%f,\"total_values\":%u,\"range\":%"PRIu64",\"history_count\":%"PRIu64",\"history_time\":%f,\"min_data_count\":%u,\"timing_values\":%u" ? "\"read_count\":%d,\"fullnonce\":%f,\"count\":%d,\"Hs\":%.15f,\"W\":%f,\"total_values\":%u,\"range\":%"PRIu64",\"history_count\":%"PRIu64",\"history_time\":%f,\"min_data_count\":%u,\"timing_values\":%u"
: "read_count=%d,fullnonce=%f,count=%d,Hs=%.15f,W=%f,total_values=%u,range=%"PRIu64",history_count=%"PRIu64",history_time=%f,min_data_count=%u,timing_values=%u", : "read_count=%d,fullnonce=%f,count=%d,Hs=%.15f,W=%f,total_values=%u,range=%"PRIu64",history_count=%"PRIu64",history_time=%f,min_data_count=%u,timing_values=%u",
@ -693,6 +710,9 @@ static void icarus_api_stats(char *buf, struct cgpu_info *cgpu, bool isjson)
(double)(info->history_time.tv_sec) (double)(info->history_time.tv_sec)
+ ((double)(info->history_time.tv_usec))/((double)1000000), + ((double)(info->history_time.tv_usec))/((double)1000000),
info->min_data_count, info->history[0].values); info->min_data_count, info->history[0].values);
*/
return root;
} }
static void icarus_shutdown(struct thr_info *thr) static void icarus_shutdown(struct thr_info *thr)

3
miner.h

@ -220,6 +220,7 @@ struct gpu_adl {
}; };
#endif #endif
struct api_data;
struct thr_info; struct thr_info;
struct work; struct work;
@ -234,7 +235,7 @@ struct device_api {
void (*reinit_device)(struct cgpu_info*); void (*reinit_device)(struct cgpu_info*);
void (*get_statline_before)(char*, struct cgpu_info*); void (*get_statline_before)(char*, struct cgpu_info*);
void (*get_statline)(char*, struct cgpu_info*); void (*get_statline)(char*, struct cgpu_info*);
void (*get_api_stats)(char*, struct cgpu_info*, bool); struct api_data *(*get_api_stats)(struct cgpu_info*);
// Thread-specific functions // Thread-specific functions
bool (*thread_prepare)(struct thr_info*); bool (*thread_prepare)(struct thr_info*);

Loading…
Cancel
Save