Browse Source

Merge pull request #247 from kanoi/master

api.c data structure + updated get_api_stats/driver-icarus.c
Con Kolivas 13 years ago
parent
commit
2ec0fb9793
4 changed files with 662 additions and 164 deletions
  1. 12 2
      API-README
  2. 579 150
      api.c
  3. 18 11
      driver-icarus.c
  4. 53 1
      miner.h

+ 12 - 2
API-README

@@ -309,13 +309,23 @@ miner.php - an example web page to access the API
 Feature Changelog for external applications using the API:
 
 
-API V1.13
+API V1.14
+
+Modified API commands:
+ 'stats' - more icarus timing stats added
+
+The internal code for handling data was rewritten (~25% of the code)
+Completely backward compatible
+
+----------
+
+API V1.13 (cgminer v2.4.4)
 
 Added API commands:
  'check'
 
 Support was added to cgminer for API access groups with the --api-groups option
-It's 100% backwards compatible with previous --api-access commands
+It's 100% backward compatible with previous --api-access commands
 
 ----------
 

File diff suppressed because it is too large
+ 579 - 150
api.c


+ 18 - 11
driver-icarus.c

@@ -676,23 +676,30 @@ static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 	return hash_count;
 }
 
-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];
 
 	// Warning, access to these is not locked - but we don't really
 	// care since hashing performance is way more important than
 	// locking access to displaying API debug 'stats'
-	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",
-		info->read_count, info->fullnonce,
-		info->count, info->Hs, info->W,
-		info->values, info->hash_count_range,
-		info->history_count,
-		(double)(info->history_time.tv_sec)
-			+ ((double)(info->history_time.tv_usec))/((double)1000000),
-		info->min_data_count, info->history[0].values);
+	// 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);
+
+	return root;
 }
 
 static void icarus_shutdown(struct thr_info *thr)

+ 53 - 1
miner.h

@@ -220,6 +220,7 @@ struct gpu_adl {
 };
 #endif
 
+struct api_data;
 struct thr_info;
 struct work;
 
@@ -234,7 +235,7 @@ struct device_api {
 	void (*reinit_device)(struct cgpu_info*);
 	void (*get_statline_before)(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
 	bool (*thread_prepare)(struct thr_info*);
@@ -793,4 +794,55 @@ extern bool successful_connect;
 extern void adl(void);
 extern void app_restart(void);
 
+enum api_data_type {
+	API_ESCAPE,
+	API_STRING,
+	API_CONST,
+	API_INT,
+	API_UINT,
+	API_UINT32,
+	API_UINT64,
+	API_DOUBLE,
+	API_ELAPSED,
+	API_BOOL,
+	API_TIMEVAL,
+	API_TIME,
+	API_MHS,
+	API_MHTOTAL,
+	API_TEMP,
+	API_UTILITY,
+	API_FREQ,
+	API_VOLTS,
+	API_HS
+};
+
+struct api_data {
+	enum api_data_type type;
+	char *name;
+	void *data;
+	bool data_was_malloc;
+	struct api_data *prev;
+	struct api_data *next;
+};
+
+extern struct api_data *api_add_escape(struct api_data *root, char *name, char *data, bool copy_data);
+extern struct api_data *api_add_string(struct api_data *root, char *name, char *data, bool copy_data);
+extern struct api_data *api_add_const(struct api_data *root, char *name, const char *data, bool copy_data);
+extern struct api_data *api_add_int(struct api_data *root, char *name, int *data, bool copy_data);
+extern struct api_data *api_add_uint(struct api_data *root, char *name, unsigned int *data, bool copy_data);
+extern struct api_data *api_add_uint32(struct api_data *root, char *name, uint32_t *data, bool copy_data);
+extern struct api_data *api_add_uint64(struct api_data *root, char *name, uint64_t *data, bool copy_data);
+extern struct api_data *api_add_double(struct api_data *root, char *name, double *data, bool copy_data);
+extern struct api_data *api_add_elapsed(struct api_data *root, char *name, double *data, bool copy_data);
+extern struct api_data *api_add_bool(struct api_data *root, char *name, bool *data, bool copy_data);
+extern struct api_data *api_add_timeval(struct api_data *root, char *name, struct timeval *data, bool copy_data);
+extern struct api_data *api_add_time(struct api_data *root, char *name, time_t *data, bool copy_data);
+extern struct api_data *api_add_mhs(struct api_data *root, char *name, double *data, bool copy_data);
+extern struct api_data *api_add_mhstotal(struct api_data *root, char *name, double *data, bool copy_data);
+extern struct api_data *api_add_temp(struct api_data *root, char *name, float *data, bool copy_data);
+extern struct api_data *api_add_utility(struct api_data *root, char *name, double *data, bool copy_data);
+extern struct api_data *api_add_freq(struct api_data *root, char *name, double *data, bool copy_data);
+extern struct api_data *api_add_volts(struct api_data *root, char *name, float *data, bool copy_data);
+extern struct api_data *api_add_hs(struct api_data *root, char *name, double *data, bool copy_data);
+
 #endif /* __MINER_H__ */

Some files were not shown because too many files changed in this diff