icarus - timing history in it's own function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
diff --git a/driver-icarus.c b/driver-icarus.c
index 1e9a684..ac1655f 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -1671,6 +1671,125 @@ void rock_send_task(unsigned char chip_no, unsigned int current_task_id, struct
return;
}
+static void process_history(struct cgpu_info *icarus, struct ICARUS_INFO *info, uint32_t nonce,
+ uint64_t hash_count, struct timeval *elapsed, struct timeval *tv_start)
+{
+ struct ICARUS_HISTORY *history0, *history;
+ struct timeval tv_history_start, tv_history_finish;
+ int count;
+ double Hs, W, fullnonce;
+ int read_time, i;
+ bool limited;
+ uint32_t values;
+ int64_t hash_count_range;
+ double Ti, Xi;
+
+ // Ignore possible end condition values ...
+ // TODO: set limitations on calculated values depending on the device
+ // to avoid crap values caused by CPU/Task Switching/Swapping/etc
+ if ((nonce & info->nonce_mask) <= END_CONDITION ||
+ (nonce & info->nonce_mask) >= (info->nonce_mask & ~END_CONDITION))
+ return;
+
+ cgtime(&tv_history_start);
+
+ history0 = &(info->history[0]);
+
+ if (history0->values == 0)
+ timeradd(tv_start, &history_sec, &(history0->finish));
+
+ Ti = (double)(elapsed->tv_sec)
+ + ((double)(elapsed->tv_usec))/((double)1000000)
+ - ((double)ICARUS_READ_TIME(info->baud));
+ Xi = (double)hash_count;
+ history0->sumXiTi += Xi * Ti;
+ history0->sumXi += Xi;
+ history0->sumTi += Ti;
+ history0->sumXi2 += Xi * Xi;
+
+ history0->values++;
+
+ if (history0->hash_count_max < hash_count)
+ history0->hash_count_max = hash_count;
+ if (history0->hash_count_min > hash_count || history0->hash_count_min == 0)
+ history0->hash_count_min = hash_count;
+
+ if (history0->values >= info->min_data_count
+ && timercmp(tv_start, &(history0->finish), >)) {
+ for (i = INFO_HISTORY; i > 0; i--)
+ memcpy(&(info->history[i]),
+ &(info->history[i-1]),
+ sizeof(struct ICARUS_HISTORY));
+
+ // Initialise history0 to zero for summary calculation
+ memset(history0, 0, sizeof(struct ICARUS_HISTORY));
+
+ // We just completed a history data set
+ // So now recalc read_time based on the whole history thus we will
+ // initially get more accurate until it completes INFO_HISTORY
+ // total data sets
+ count = 0;
+ for (i = 1 ; i <= INFO_HISTORY; i++) {
+ history = &(info->history[i]);
+ if (history->values >= MIN_DATA_COUNT) {
+ count++;
+
+ history0->sumXiTi += history->sumXiTi;
+ history0->sumXi += history->sumXi;
+ history0->sumTi += history->sumTi;
+ history0->sumXi2 += history->sumXi2;
+ history0->values += history->values;
+
+ if (history0->hash_count_max < history->hash_count_max)
+ history0->hash_count_max = history->hash_count_max;
+ if (history0->hash_count_min > history->hash_count_min || history0->hash_count_min == 0)
+ history0->hash_count_min = history->hash_count_min;
+ }
+ }
+
+ // All history data
+ Hs = (history0->values*history0->sumXiTi - history0->sumXi*history0->sumTi)
+ / (history0->values*history0->sumXi2 - history0->sumXi*history0->sumXi);
+ W = history0->sumTi/history0->values - Hs*history0->sumXi/history0->values;
+ hash_count_range = history0->hash_count_max - history0->hash_count_min;
+ values = history0->values;
+
+ // Initialise history0 to zero for next data set
+ memset(history0, 0, sizeof(struct ICARUS_HISTORY));
+
+ fullnonce = W + Hs * (((double)0xffffffff) + 1);
+ read_time = SECTOMS(fullnonce) - ICARUS_READ_REDUCE;
+ if (info->read_time_limit > 0 && read_time > info->read_time_limit) {
+ read_time = info->read_time_limit;
+ limited = true;
+ } else
+ limited = false;
+
+ info->Hs = Hs;
+ info->read_time = read_time;
+
+ info->fullnonce = fullnonce;
+ info->count = count;
+ info->W = W;
+ info->values = values;
+ info->hash_count_range = hash_count_range;
+
+ if (info->min_data_count < MAX_MIN_DATA_COUNT)
+ info->min_data_count *= 2;
+ else if (info->timing_mode == MODE_SHORT)
+ info->do_icarus_timing = false;
+
+ applog(LOG_WARNING, "%s%d Re-estimate: Hs=%e W=%e read_time=%dms%s fullnonce=%.3fs",
+ icarus->drv->name, icarus->device_id, Hs, W, read_time,
+ limited ? " (limited)" : "", fullnonce);
+ }
+ info->history_count++;
+ cgtime(&tv_history_finish);
+
+ timersub(&tv_history_finish, &tv_history_start, &tv_history_finish);
+ timeradd(&tv_history_finish, &(info->history_time), &(info->history_time));
+}
+
static int64_t icarus_scanwork(struct thr_info *thr)
{
struct cgpu_info *icarus = thr->cgpu;
@@ -1682,20 +1801,10 @@ static int64_t icarus_scanwork(struct thr_info *thr)
uint32_t nonce;
int64_t hash_count = 0;
struct timeval tv_start, tv_finish, elapsed;
- struct timeval tv_history_start, tv_history_finish;
- double Ti, Xi;
- int curr_hw_errors, i;
+ int curr_hw_errors;
bool was_hw_error;
struct work *work;
-
- struct ICARUS_HISTORY *history0, *history;
- int count;
- double Hs, W, fullnonce;
- int read_time;
- bool limited;
int64_t estimate_hashes;
- uint32_t values;
- int64_t hash_count_range;
if (unlikely(share_work_tdiff(icarus) > info->fail_time)) {
if (info->failing) {
@@ -1814,111 +1923,8 @@ static int64_t icarus_scanwork(struct thr_info *thr)
nonce, (long unsigned int)hash_count,
(long)elapsed.tv_sec, (long)elapsed.tv_usec);
- // Ignore possible end condition values ... and hw errors
- // TODO: set limitations on calculated values depending on the device
- // to avoid crap values caused by CPU/Task Switching/Swapping/etc
- if (info->do_icarus_timing
- && !was_hw_error
- && ((nonce & info->nonce_mask) > END_CONDITION)
- && ((nonce & info->nonce_mask) < (info->nonce_mask & ~END_CONDITION))) {
- cgtime(&tv_history_start);
-
- history0 = &(info->history[0]);
-
- if (history0->values == 0)
- timeradd(&tv_start, &history_sec, &(history0->finish));
-
- Ti = (double)(elapsed.tv_sec)
- + ((double)(elapsed.tv_usec))/((double)1000000)
- - ((double)ICARUS_READ_TIME(info->baud));
- Xi = (double)hash_count;
- history0->sumXiTi += Xi * Ti;
- history0->sumXi += Xi;
- history0->sumTi += Ti;
- history0->sumXi2 += Xi * Xi;
-
- history0->values++;
-
- if (history0->hash_count_max < hash_count)
- history0->hash_count_max = hash_count;
- if (history0->hash_count_min > hash_count || history0->hash_count_min == 0)
- history0->hash_count_min = hash_count;
-
- if (history0->values >= info->min_data_count
- && timercmp(&tv_start, &(history0->finish), >)) {
- for (i = INFO_HISTORY; i > 0; i--)
- memcpy(&(info->history[i]),
- &(info->history[i-1]),
- sizeof(struct ICARUS_HISTORY));
-
- // Initialise history0 to zero for summary calculation
- memset(history0, 0, sizeof(struct ICARUS_HISTORY));
-
- // We just completed a history data set
- // So now recalc read_time based on the whole history thus we will
- // initially get more accurate until it completes INFO_HISTORY
- // total data sets
- count = 0;
- for (i = 1 ; i <= INFO_HISTORY; i++) {
- history = &(info->history[i]);
- if (history->values >= MIN_DATA_COUNT) {
- count++;
-
- history0->sumXiTi += history->sumXiTi;
- history0->sumXi += history->sumXi;
- history0->sumTi += history->sumTi;
- history0->sumXi2 += history->sumXi2;
- history0->values += history->values;
-
- if (history0->hash_count_max < history->hash_count_max)
- history0->hash_count_max = history->hash_count_max;
- if (history0->hash_count_min > history->hash_count_min || history0->hash_count_min == 0)
- history0->hash_count_min = history->hash_count_min;
- }
- }
-
- // All history data
- Hs = (history0->values*history0->sumXiTi - history0->sumXi*history0->sumTi)
- / (history0->values*history0->sumXi2 - history0->sumXi*history0->sumXi);
- W = history0->sumTi/history0->values - Hs*history0->sumXi/history0->values;
- hash_count_range = history0->hash_count_max - history0->hash_count_min;
- values = history0->values;
-
- // Initialise history0 to zero for next data set
- memset(history0, 0, sizeof(struct ICARUS_HISTORY));
-
- fullnonce = W + Hs * (((double)0xffffffff) + 1);
- read_time = SECTOMS(fullnonce) - ICARUS_READ_REDUCE;
- if (info->read_time_limit > 0 && read_time > info->read_time_limit) {
- read_time = info->read_time_limit;
- limited = true;
- } else
- limited = false;
-
- info->Hs = Hs;
- info->read_time = read_time;
-
- info->fullnonce = fullnonce;
- info->count = count;
- info->W = W;
- info->values = values;
- info->hash_count_range = hash_count_range;
-
- if (info->min_data_count < MAX_MIN_DATA_COUNT)
- info->min_data_count *= 2;
- else if (info->timing_mode == MODE_SHORT)
- info->do_icarus_timing = false;
-
- applog(LOG_WARNING, "%s%d Re-estimate: Hs=%e W=%e read_time=%dms%s fullnonce=%.3fs",
- icarus->drv->name, icarus->device_id, Hs, W, read_time,
- limited ? " (limited)" : "", fullnonce);
- }
- info->history_count++;
- cgtime(&tv_history_finish);
-
- timersub(&tv_history_finish, &tv_history_start, &tv_history_finish);
- timeradd(&tv_history_finish, &(info->history_time), &(info->history_time));
- }
+ if (info->do_icarus_timing && !was_hw_error)
+ process_history(icarus, info, nonce, hash_count, &elapsed, &tv_start);
out:
free_work(work);