本文整理汇总了C++中cgtime函数的典型用法代码示例。如果您正苦于以下问题:C++ cgtime函数的具体用法?C++ cgtime怎么用?C++ cgtime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cgtime函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: opencl_thread_prepare
static bool opencl_thread_prepare(struct thr_info *thr)
{
char name[256];
struct timeval now;
struct cgpu_info *cgpu = thr->cgpu;
int gpu = cgpu->device_id;
int virtual_gpu = cgpu->virtual_gpu;
int i = thr->id;
static bool failmessage = false;
int buffersize = BUFFERSIZE;
if (!blank_res)
blank_res = (uint32_t *)calloc(buffersize, 1);
if (!blank_res) {
applog(LOG_ERR, "Failed to calloc in opencl_thread_init");
return false;
}
strcpy(name, "");
applog(LOG_INFO, "Init GPU thread %i GPU %i virtual GPU %i", i, gpu, virtual_gpu);
clStates[i] = initCl(virtual_gpu, name, sizeof(name), &cgpu->algorithm);
if (!clStates[i]) {
#ifdef HAVE_CURSES
if (use_curses)
enable_curses();
#endif
applog(LOG_ERR, "Failed to init GPU thread %d, disabling device %d", i, gpu);
if (!failmessage) {
applog(LOG_ERR, "Restarting the GPU from the menu will not fix this.");
applog(LOG_ERR, "Re-check your configuration and try restarting.");
failmessage = true;
#ifdef HAVE_CURSES
char *buf;
if (use_curses) {
buf = curses_input("Press enter to continue");
if (buf)
free(buf);
}
#endif
}
cgpu->deven = DEV_DISABLED;
cgpu->status = LIFE_NOSTART;
dev_error(cgpu, REASON_DEV_NOSTART);
return false;
}
if (!cgpu->name)
cgpu->name = strdup(name);
if (!cgpu->kernelname)
cgpu->kernelname = strdup("ckolivas");
applog(LOG_INFO, "initCl() finished. Found %s", name);
cgtime(&now);
get_datestamp(cgpu->init, sizeof(cgpu->init), &now);
have_opencl = true;
return true;
}
开发者ID:evolvia31,项目名称:sgminer-gridseed-GBlade,代码行数:60,代码来源:driver-opencl.c
示例2: gridseed_scanhash
static int64_t gridseed_scanhash(struct thr_info *thr, struct work *work, int64_t __maybe_unused max_nonce)
{
struct cgpu_info *gridseed = thr->cgpu;
GRIDSEED_INFO *info = gridseed->device_data;
unsigned char buf[GRIDSEED_READ_SIZE];
int ret = 0;
struct timeval old_scanhash_time = info->scanhash_time;
int elapsed_ms;
while (!thr->work_restart && (ret = gc3355_get_data(gridseed, buf, GRIDSEED_READ_SIZE)) == 0) {
if (buf[0] == 0x55 || buf[1] == 0x20) {
uint32_t nonce = le32toh(*(uint32_t *)(buf+4));
uint32_t chip = nonce / ((uint32_t)0xffffffff / info->chips);
info->nonce_count[chip]++;
if (!submit_nonce(thr, work, nonce))
info->error_count[chip]++;
} else {
applog(LOG_ERR, "Unrecognized response from %i", gridseed->device_id);
return -1;
}
}
if (ret != 0 && ret != LIBUSB_ERROR_TIMEOUT) {
applog(LOG_ERR, "No response from %i", gridseed->device_id);
return -1;
}
cgtime(&info->scanhash_time);
elapsed_ms = ms_tdiff(&info->scanhash_time, &old_scanhash_time);
return GRIDSEED_HASH_SPEED * (double)elapsed_ms * (double)(info->freq * info->chips);
}
开发者ID:Tomcatt,项目名称:sgminer,代码行数:30,代码来源:driver-gridseed.c
示例3: _applog
/*
* log function
*/
void _applog(int prio, const char *str, bool force)
{
#ifdef HAVE_SYSLOG_H
if (use_syslog) {
syslog(prio, "%s", str);
}
#else
if (0) {}
#endif
else {
char datetime[64];
struct timeval tv = {0, 0};
struct tm *tm;
cgtime(&tv);
const time_t tmp_time = tv.tv_sec;
tm = localtime(&tmp_time);
/* Day changed. */
if (opt_log_show_date && (last_date_output_day != tm->tm_mday))
{
last_date_output_day = tm->tm_mday;
char date_output_str[64];
snprintf(date_output_str, sizeof(date_output_str), "Log date is now %d-%02d-%02d",
tm->tm_year + 1900,
tm->tm_mon + 1,
tm->tm_mday);
_applog(prio, date_output_str, force);
}
if (opt_log_show_date)
{
snprintf(datetime, sizeof(datetime), "[%d-%02d-%02d %02d:%02d:%02d] ",
tm->tm_year + 1900,
tm->tm_mon + 1,
tm->tm_mday,
tm->tm_hour,
tm->tm_min,
tm->tm_sec);
}
else
{
snprintf(datetime, sizeof(datetime), "[%02d:%02d:%02d] ",
tm->tm_hour,
tm->tm_min,
tm->tm_sec);
}
/* Only output to stderr if it's not going to the screen as well */
if (!isatty(fileno((FILE *)stderr))) {
fprintf(stderr, "%s%s\n", datetime, str); /* atomic write to stderr */
fflush(stderr);
}
my_log_curses(prio, datetime, str, force);
}
}
开发者ID:Bufius,项目名称:sgminer,代码行数:62,代码来源:logging.c
示例4: gridseed_prepare_work
static bool gridseed_prepare_work(struct thr_info __maybe_unused *thr, struct work *work) {
struct cgpu_info *gridseed = thr->cgpu;
GRIDSEED_INFO *info = gridseed->device_data;
cgtime(&info->scanhash_time);
gc3355_send_cmds(gridseed, str_ltc_reset);
usb_buffer_clear(gridseed);
return gridseed_send_task(gridseed, work);
}
开发者ID:Tomcatt,项目名称:sgminer,代码行数:9,代码来源:driver-gridseed.c
示例5: bitforce_thread_prepare
static bool bitforce_thread_prepare(struct thr_info *thr)
{
struct cgpu_info *bitforce = thr->cgpu;
struct timeval now;
cgtime(&now);
get_datestamp(bitforce->init, &now);
return true;
}
开发者ID:AxelWalsleben,项目名称:cgminer,代码行数:10,代码来源:driver-bitforce.c
示例6: bitfury_prepare
static bool bitfury_prepare(struct thr_info *thr)
{
struct timeval now;
struct cgpu_info *cgpu = thr->cgpu;
cgtime(&now);
get_datestamp(cgpu->init, &now);
applog(LOG_INFO, "INFO bitfury_prepare");
return true;
}
开发者ID:CSRedRat,项目名称:cgminer,代码行数:11,代码来源:driver-bitfury.c
示例7: spondoolies_prepare_sp30
static bool spondoolies_prepare_sp30(struct thr_info *thr)
{
struct cgpu_info *spondoolies_sp30 = thr->cgpu;
struct timeval now;
assert(spondoolies_sp30);
cgtime(&now);
/* FIXME: Vladik */
#if NEED_FIX
get_datestamp(spondoolies_sp30->init, &now);
#endif
return true;
}
开发者ID:60E,项目名称:cgminer,代码行数:13,代码来源:driver-spondoolies-sp30.c
示例8: pthread_setcanceltype
void *miner_thread(void *userdata)
{
struct thr_info *mythr = userdata;
struct cgpu_info *cgpu = mythr->cgpu;
struct device_drv *drv = cgpu->drv;
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
char threadname[20];
snprintf(threadname, 20, "miner_%s", cgpu->proc_repr_ns);
RenameThread(threadname);
if (drv->thread_init && !drv->thread_init(mythr)) {
dev_error(cgpu, REASON_THREAD_FAIL_INIT);
for (struct cgpu_info *slave = cgpu->next_proc; slave && !slave->threads; slave = slave->next_proc)
dev_error(slave, REASON_THREAD_FAIL_INIT);
__thr_being_msg(LOG_ERR, mythr, "failure, exiting");
goto out;
}
thread_reportout(mythr);
applog(LOG_DEBUG, "Popping ping in miner thread");
notifier_read(mythr->notifier); // Wait for a notification to start
cgtime(&cgpu->cgminer_stats.start_tv);
if (drv->minerloop)
drv->minerloop(mythr);
else
minerloop_scanhash(mythr);
__thr_being_msg(LOG_NOTICE, mythr, "shutting down");
out: ;
struct cgpu_info *proc = cgpu;
do
{
proc->deven = DEV_DISABLED;
proc->status = LIFE_DEAD2;
}
while ( (proc = proc->next_proc) && !proc->threads);
mythr->getwork = 0;
mythr->has_pth = false;
cgsleep_ms(1000);
if (drv->thread_shutdown)
drv->thread_shutdown(mythr);
notifier_destroy(mythr->notifier);
return NULL;
}
开发者ID:medikid,项目名称:MaxSharesMiner,代码行数:50,代码来源:deviceapi.c
示例9: usec_stamp
unsigned long usec_stamp(void)
{
static unsigned long long int first_usec = 0;
struct timeval tv;
unsigned long long int curr_usec;
cgtime(&tv);
curr_usec = tv.tv_sec * 1000000 + tv.tv_usec;
if (first_usec == 0) {
first_usec = curr_usec;
curr_usec = 0;
} else
curr_usec -= first_usec;
return curr_usec;
}
开发者ID:60E,项目名称:cgminer,代码行数:15,代码来源:driver-spondoolies-sp30.c
示例10: hfa_prepare
static bool hfa_prepare(struct thr_info *thr)
{
struct cgpu_info *hashfast = thr->cgpu;
struct hashfast_info *info = hashfast->device_data;
struct timeval now;
mutex_init(&info->lock);
if (pthread_create(&info->read_thr, NULL, hfa_read, (void *)thr))
quit(1, "Failed to pthread_create read thr in hfa_prepare");
cgtime(&now);
get_datestamp(hashfast->init, sizeof(hashfast->init), &now);
return true;
}
开发者ID:uraymeiviar,项目名称:cgminer,代码行数:15,代码来源:driver-hashfast.c
示例11: _applog
/*
* log function
*/
void _applog(int prio, const char *str, bool force)
{
#ifdef HAVE_SYSLOG_H
if (use_syslog) {
syslog(prio, "%s", str);
}
#else
if (0) {}
#endif
else {
char datetime[64];
struct timeval tv = {0, 0};
struct tm *tm;
cgtime(&tv);
const time_t tmp_time = tv.tv_sec;
tm = localtime(&tmp_time);
snprintf(datetime, sizeof(datetime), " [%d-%02d-%02d %02d:%02d:%02d] ",
tm->tm_year + 1900,
tm->tm_mon + 1,
tm->tm_mday,
tm->tm_hour,
tm->tm_min,
tm->tm_sec);
/* Only output to stderr if it's not going to the screen as well */
if (!isatty(fileno((FILE *)stderr))) {
fprintf(stderr, "%s%s\n", datetime, str); /* atomic write to stderr */
fflush(stderr);
}
if(g_logfile_enable) {
if(!g_log_file) {
g_log_file = fopen(g_logfile_path, g_logfile_openflag);
}
if(g_log_file) {
fwrite(datetime, strlen(datetime), 1, g_log_file);
fwrite(str, strlen(str), 1, g_log_file);
fwrite("\n", 1, 1, g_log_file);
fflush(g_log_file);
}
}
my_log_curses(prio, datetime, str, force);
}
}
开发者ID:AntMinerCE,项目名称:meta-s3,代码行数:51,代码来源:logging.c
示例12: hfa_prepare
static bool hfa_prepare(struct thr_info *thr)
{
struct cgpu_info *hashfast = thr->cgpu;
struct hashfast_info *info = hashfast->device_data;
struct timeval now;
mutex_init(&info->lock);
if (pthread_create(&info->read_thr, NULL, hfa_read, (void *)thr))
quit(1, "Failed to pthread_create read thr in hfa_prepare");
cgtime(&now);
get_datestamp(hashfast->init, sizeof(hashfast->init), &now);
hashfast->last_device_valid_work = time(NULL);
info->resets = 0;
hfa_set_fanspeed(hashfast, info, opt_hfa_fan_default);
return true;
}
开发者ID:fgrotta,项目名称:cgminer,代码行数:18,代码来源:driver-hashfast.c
示例13: isdupnonce
bool isdupnonce(struct cgpu_info *cgpu, struct work *work, uint32_t nonce)
{
struct dupdata *dup = (struct dupdata *)(cgpu->dup_data);
struct timeval now;
bool unique = true;
K_ITEM *item;
if (!dup)
return false;
cgtime(&now);
dup->checked++;
K_WLOCK(dup->nfree_list);
item = dup->nonce_list->tail;
while (unique && item) {
if (DATAN(item)->work_id == work->id && DATAN(item)->nonce == nonce) {
unique = false;
applog(LOG_WARNING, "%s%d: Duplicate nonce %08x",
cgpu->drv->name, cgpu->device_id, nonce);
} else
item = item->prev;
}
if (unique) {
item = k_unlink_head(dup->nfree_list);
DATAN(item)->work_id = work->id;
DATAN(item)->nonce = nonce;
memcpy(&(DATAN(item)->when), &now, sizeof(now));
k_add_head(dup->nonce_list, item);
}
item = dup->nonce_list->tail;
while (item && tdiff(&(DATAN(item)->when), &now) > dup->timelimit) {
item = k_unlink_tail(dup->nonce_list);
k_add_head(dup->nfree_list, item);
item = dup->nonce_list->tail;
}
K_WUNLOCK(dup->nfree_list);
if (!unique)
dup->dup++;
return !unique;
}
开发者ID:1credit,项目名称:cgminer,代码行数:42,代码来源:noncedup.c
示例14: _applog
/*
* log function
*/
void _applog(int prio, const char *str)
{
#ifdef HAVE_SYSLOG_H
if (use_syslog) {
syslog(prio, "%s", str);
}
#else
if (0) {}
#endif
else {
char datetime[64];
struct timeval tv = {0, 0};
struct tm *tm;
cgtime(&tv);
const time_t tmp_time = tv.tv_sec;
tm = localtime(&tmp_time);
sprintf(datetime, " [%d-%02d-%02d %02d:%02d:%02d] ",
tm->tm_year + 1900,
tm->tm_mon + 1,
tm->tm_mday,
tm->tm_hour,
tm->tm_min,
tm->tm_sec);
/* Only output to stderr if it's not going to the screen as well */
if (!isatty(fileno((FILE *)stderr))) {
fprintf(stderr, "%s%s\n", datetime, str); /* atomic write to stderr */
fflush(stderr);
}
my_log_curses(prio, datetime, str);
}
}
开发者ID:AxelWalsleben,项目名称:cgminer,代码行数:39,代码来源:logging.c
示例15: pthread_detach
/* We have only one thread that ever re-initialises GPUs, thus if any GPU
* init command fails due to a completely wedged GPU, the thread will never
* return, unable to harm other GPUs. If it does return, it means we only had
* a soft failure and then the reinit_gpu thread is ready to tackle another
* GPU */
void *reinit_gpu(void *userdata)
{
struct thr_info *mythr = userdata;
struct cgpu_info *cgpu;
struct thr_info *thr;
struct timeval now;
char name[256];
int thr_id;
int gpu;
pthread_detach(pthread_self());
select_cgpu:
cgpu = tq_pop(mythr->q, NULL);
if (!cgpu)
goto out;
if (clDevicesNum() != nDevs) {
applog(LOG_WARNING, "Hardware not reporting same number of active devices, will not attempt to restart GPU");
goto out;
}
gpu = cgpu->device_id;
for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
thr = get_thread(thr_id);
cgpu = thr->cgpu;
if (cgpu->drv->drv_id != DRIVER_opencl)
continue;
if (dev_from_id(thr_id) != gpu)
continue;
thr = get_thread(thr_id);
if (!thr) {
applog(LOG_WARNING, "No reference to thread %d exists", thr_id);
continue;
}
thr->rolling = thr->cgpu->rolling = 0;
/* Reports the last time we tried to revive a sick GPU */
cgtime(&thr->sick);
if (!pthread_cancel(thr->pth)) {
applog(LOG_WARNING, "Thread %d still exists, killing it off", thr_id);
} else
applog(LOG_WARNING, "Thread %d no longer exists", thr_id);
}
for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
int virtual_gpu;
thr = get_thread(thr_id);
cgpu = thr->cgpu;
if (cgpu->drv->drv_id != DRIVER_opencl)
continue;
if (dev_from_id(thr_id) != gpu)
continue;
virtual_gpu = cgpu->virtual_gpu;
/* Lose this ram cause we may get stuck here! */
//tq_freeze(thr->q);
thr->q = tq_new();
if (!thr->q)
quit(1, "Failed to tq_new in reinit_gpu");
/* Lose this ram cause we may dereference in the dying thread! */
//free(clState);
applog(LOG_INFO, "Reinit GPU thread %d", thr_id);
clStates[thr_id] = initCl(virtual_gpu, name, sizeof(name));
if (!clStates[thr_id]) {
applog(LOG_ERR, "Failed to reinit GPU thread %d", thr_id);
goto select_cgpu;
}
applog(LOG_INFO, "initCl() finished. Found %s", name);
if (unlikely(thr_info_create(thr, NULL, miner_thread, thr))) {
applog(LOG_ERR, "thread %d create failed", thr_id);
return NULL;
}
applog(LOG_WARNING, "Thread %d restarted", thr_id);
}
cgtime(&now);
get_datestamp(cgpu->init, sizeof(cgpu->init), &now);
for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
thr = get_thread(thr_id);
cgpu = thr->cgpu;
if (cgpu->drv->drv_id != DRIVER_opencl)
continue;
if (dev_from_id(thr_id) != gpu)
continue;
cgsem_post(&thr->sem);
//.........这里部分代码省略.........
开发者ID:jedigras,项目名称:sph-sgminer,代码行数:101,代码来源:driver-opencl.c
示例16: avalon2_scanhash
static int64_t avalon2_scanhash(struct thr_info *thr)
{
struct avalon2_pkg send_pkg;
struct timeval current_stratum;
struct pool *pool;
struct cgpu_info *avalon2 = thr->cgpu;
struct avalon2_info *info = avalon2->device_data;
int64_t h;
uint32_t tmp, range, start;
int i;
if (thr->work_restart || thr->work_update || !info->first) {
applog(LOG_DEBUG, "Avalon2: New stratum: restart: %d, update: %d, first: %d",
thr->work_restart, thr->work_update, info->first);
thr->work_update = false;
thr->work_restart = false;
get_work(thr, thr->id); /* Make sure pool is ready */
pool = current_pool();
if (!pool->has_stratum)
quit(1, "Avalon2: Miner Manager have to use stratum pool");
if (pool->coinbase_len > AVA2_P_COINBASE_SIZE) {
applog(LOG_ERR, "Avalon2: Miner Manager pool coinbase length have to less then %d", AVA2_P_COINBASE_SIZE);
return 0;
}
if (pool->merkles > AVA2_P_MERKLES_COUNT) {
applog(LOG_ERR, "Avalon2: Miner Manager merkles have to less then %d", AVA2_P_MERKLES_COUNT);
return 0;
}
cgtime(&info->last_stratum);
cg_rlock(&pool->data_lock);
info->pool_no = pool->pool_no;
copy_pool_stratum(pool);
avalon2_stratum_pkgs(info->fd, pool, thr);
cg_runlock(&pool->data_lock);
/* Configuer the parameter from outside */
adjust_fan(info);
info->set_voltage = opt_avalon2_voltage_min;
info->set_frequency = opt_avalon2_freq_min;
/* Set the Fan, Voltage and Frequency */
memset(send_pkg.data, 0, AVA2_P_DATA_LEN);
tmp = be32toh(info->fan_pwm);
memcpy(send_pkg.data, &tmp, 4);
applog(LOG_ERR, "Avalon2: Temp max: %d, Cut off temp: %d",
get_current_temp_max(info), opt_avalon2_overheat);
if (get_current_temp_max(info) >= opt_avalon2_overheat)
tmp = encode_voltage(0);
else
tmp = encode_voltage(info->set_voltage);
tmp = be32toh(tmp);
memcpy(send_pkg.data + 4, &tmp, 4);
tmp = be32toh(info->set_frequency);
memcpy(send_pkg.data + 8, &tmp, 4);
/* Configure the nonce2 offset and range */
range = 0xffffffff / total_devices;
start = range * avalon2->device_id;
tmp = be32toh(start);
memcpy(send_pkg.data + 12, &tmp, 4);
tmp = be32toh(range);
memcpy(send_pkg.data + 16, &tmp, 4);
/* Package the data */
avalon2_init_pkg(&send_pkg, AVA2_P_SET, 1, 1);
while (avalon2_send_pkg(info->fd, &send_pkg, thr) != AVA2_SEND_OK)
;
if (unlikely(info->first < 2))
info->first++;
}
/* Stop polling the device if there is no stratum in 3 minutes, network is down */
cgtime(¤t_stratum);
if (tdiff(¤t_stratum, &(info->last_stratum)) > (double)(3.0 * 60.0))
return 0;
polling(thr);
h = 0;
for (i = 0; i < AVA2_DEFAULT_MODULARS; i++) {
h += info->enable[i] ? (info->local_work[i] - info->hw_work[i]) : 0;
}
return h * 0xffffffff;
}
开发者ID:february10,项目名称:appDemo,代码行数:94,代码来源:driver-avalon2.c
示例17: ztex_prepare
static bool ztex_prepare(struct thr_info *thr)
{
struct timeval now;
struct cgpu_info *cgpu = thr->cgpu;
struct libztex_device *ztex = cgpu->device_ztex;
cgtime(&now);
get_datestamp(cgpu->init, &now);
ztex_selectFpga(ztex);
if (libztex_configureFpga(ztex) != 0) {
libztex_resetFpga(ztex);
ztex_releaseFpga(ztex);
applog(LOG_ERR, "%s: Disabling!", thr->cgpu->device_ztex->repr);
thr->cgpu->deven = DEV_DISABLED;
return true;
}
// KRAMBLE Handle options, based on get_options in driver-icarus.c
// Use as --ztex-clock freqM:freqMaxM
// Multiple comma separated vaues are allowed eg 160:180,180:184
{ // Bare block to isolate variables
char err_buf[BUFSIZ+1];
char buf[BUFSIZ+1];
char *ptr, *comma, *colon, *colon2;
size_t max;
int i, tmp;
int this_option_offset = ++option_offset;
if (opt_ztex_clock == NULL)
buf[0] = '\0';
else {
ptr = opt_ztex_clock;
for (i = 0; i < this_option_offset; i++) {
comma = strchr(ptr, ',');
if (comma == NULL)
break;
ptr = comma + 1;
}
comma = strchr(ptr, ',');
if (comma == NULL)
max = strlen(ptr);
else
max = comma - ptr;
if (max > BUFSIZ)
max = BUFSIZ;
strncpy(buf, ptr, max);
buf[max] = '\0';
}
if (*buf) {
colon = strchr(buf, ':');
if (colon)
*(colon++) = '\0';
if (*buf) {
tmp = atoi(buf);
if (tmp >= 100 && tmp <= 250)
ztex->freqM = ztex->freqMDefault = tmp/4 - 1; // NB 4Mhz units
else {
sprintf(err_buf, "Invalid ztex_clock must be between 100 and 250", buf);
quit(1, err_buf);
}
}
if (colon && *colon) {
tmp = atoi(colon);
if (tmp >= 100 && tmp <= 250) {
if (tmp/4 - 1 >= ztex->freqM)
{
ztex->freqMaxM = tmp/4 - 1; // NB 4Mhz units
// If both initial and max were set, and were the same, lock the clock
if (ztex->freqMDefault == ztex->freqMaxM)
ztex->lockClock = 1;
}
else
{
sprintf(err_buf, "Invalid ztex_clock max must be less than min", buf);
quit(1, err_buf);
}
}
else {
sprintf(err_buf, "Invalid ztex_clock must be between 100 and 250", buf);
quit(1, err_buf);
}
}
}
} // End bare block
ztex->freqM = ztex->freqMaxM+1; // KRAMBLE is in original
// ztex_updateFreq(ztex); // KRAMBLE Was already commented out in original
//.........这里部分代码省略.........
开发者ID:SuperHanZi,项目名称:FPGA-Litecoin-Miner,代码行数:101,代码来源:driver-ztex.c
示例18: bitforce_get_result
static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
{
struct cgpu_info *bitforce = thr->cgpu;
unsigned int delay_time_ms;
struct timeval elapsed;
struct timeval now;
char buf[BITFORCE_BUFSIZ+1];
int amount;
char *pnoncebuf;
uint32_t nonce;
while (1) {
if (unlikely(thr->work_restart))
return 0;
mutex_lock(&bitforce->device_mutex);
usb_write(bitforce, BITFORCE_WORKSTATUS, BITFORCE_WORKSTATUS_LEN, &amount, C_REQUESTWORKSTATUS);
usb_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETWORKSTATUS);
mutex_unlock(&bitforce->device_mutex);
cgtime(&now);
timersub(&now, &bitforce->work_start_tv, &elapsed);
if (elapsed.tv_sec >= BITFORCE_LONG_TIMEOUT_S) {
applog(LOG_ERR, "%s%i: took %ldms - longer than %dms",
bitforce->drv->name, bitforce->device_id,
tv_to_ms(elapsed), BITFORCE_LONG_TIMEOUT_MS);
return 0;
}
if (amount > 0 && buf[0] && strncasecmp(buf, "B", 1)) /* BFL does not respond during throttling */
break;
/* if BFL is throttling, no point checking so quickly */
delay_time_ms = (buf[0] ? BITFORCE_CHECK_INTERVAL_MS : 2 * WORK_CHECK_INTERVAL_MS);
nmsleep(delay_time_ms);
bitforce->wait_ms += delay_time_ms;
}
if (elapsed.tv_sec > BITFORCE_TIMEOUT_S) {
applog(LOG_ERR, "%s%i: took %ldms - longer than %dms",
bitforce->drv->name, bitforce->device_id,
tv_to_ms(elapsed), BITFORCE_TIMEOUT_MS);
dev_error(bitforce, REASON_DEV_OVER_HEAT);
/* Only return if we got nothing after timeout - there still may be results */
if (amount == 0)
return 0;
} else if (!strncasecmp(buf, BITFORCE_EITHER, BITFORCE_EITHER_LEN)) {
/* Simple timing adjustment. Allow a few polls to cope with
* OS timer delays being variably reliable. wait_ms will
* always equal sleep_ms when we've waited greater than or
* equal to the result return time.*/
delay_time_ms = bitforce->sleep_ms;
if (bitforce->wait_ms > bitforce->sleep_ms + (WORK_CHECK_INTERVAL_MS * 2))
bitforce->sleep_ms += (bitforce->wait_ms - bitforce->sleep_ms) / 2;
else if (bitforce->wait_ms == bitforce->sleep_ms) {
if (bitforce->sleep_ms > WORK_CHECK_INTERVAL_MS)
bitforce->sleep_ms -= WORK_CHECK_INTERVAL_MS;
else if (bitforce->sleep_ms > BITFORCE_CHECK_INTERVAL_MS)
bitforce->sleep_ms -= BITFORCE_CHECK_INTERVAL_MS;
}
if (delay_time_ms != bitforce->sleep_ms)
applog(LOG_DEBUG, "%s%i: Wait time changed to: %d, waited %u",
bitforce->drv->name, bitforce->device_id,
bitforce->sleep_ms, bitforce->wait_ms);
/* Work out the average time taken. Float for calculation, uint for display */
bitforce->avg_wait_f += (tv_to_ms(elapsed) - bitforce->avg_wait_f) / TIME_AVG_CONSTANT;
bitforce->avg_wait_d = (unsigned int) (bitforce->avg_wait_f + 0.5);
}
applog(LOG_DEBUG, "%s%i: waited %dms until %s",
bitforce->drv->name, bitforce->device_id,
bitforce->wait_ms, buf);
if (!strncasecmp(buf, BITFORCE_NO_NONCE, BITFORCE_NO_NONCE_MATCH))
return bitforce->nonces; /* No valid nonce found */
else if (!strncasecmp(buf, BITFORCE_IDLE, BITFORCE_IDLE_MATCH))
return 0; /* Device idle */
else if (strncasecmp(buf, BITFORCE_NONCE, BITFORCE_NONCE_LEN)) {
bitforce->hw_errors++;
applog(LOG_WARNING, "%s%i: Error: Get result reports: %s",
bitforce->drv->name, bitforce->device_id, buf);
bitforce_initialise(bitforce, true);
return 0;
}
pnoncebuf = &buf[12];
while (1) {
hex2bin((void*)&nonce, pnoncebuf, 4);
#ifndef __BIG_ENDIAN__
nonce = swab32(nonce);
#endif
if (unlikely(bitforce->nonce_range && (nonce >= work->blk.nonce ||
(work->blk.nonce > 0 && nonce < work->blk.nonce - bitforce->nonces - 1)))) {
applog(LOG_WARNING, "%s%i: Disabling broken nonce range support",
bitforce->drv->name, bitforce->device_id);
//.........这里部分代码省略.........
开发者ID:AxelWalsleben,项目名称:cgminer,代码行数:101,代码来源:driver-bitforce.c
示例19: bitforce_send_work
//.........这里部分代码省略.........
cmd = BITFORCE_SENDRANGE;
len = BITFORCE_SENDRANGE_LEN;
} else {
cmd = BITFORCE_SENDWORK;
len = BITFORCE_SENDWORK_LEN;
}
mutex_lock(&bitforce->device_mutex);
if ((err = usb_write(bitforce, cmd, len, &amount, C_REQUESTSENDWORK)) < 0 || amount != len) {
mutex_unlock(&bitforce->device_mutex);
applog(LOG_ERR, "%s%i: request send work failed (%d:%d)",
bitforce->drv->name, bitforce->device_id, amount, err);
return false;
}
if ((err = usb_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_REQUESTSENDWORKSTATUS)) < 0) {
mutex_unlock(&bitforce->device_mutex);
applog(LOG_ERR, "%s%d: read request send work status failed (%d:%d)",
bitforce->drv->name, bitforce->device_id, amount, err);
return false;
}
if (amount == 0 || !buf[0] || !strncasecmp(buf, "B", 1)) {
mutex_unlock(&bitforce->device_mutex);
nmsleep(WORK_CHECK_INTERVAL_MS);
goto re_send;
} else if (unlikely(strncasecmp(buf, "OK", 2))) {
mutex_unlock(&bitforce->device_mutex);
if (bitforce->nonce_range) {
applog(LOG_WARNING, "%s%i: Does not support nonce range, disabling",
bitforce->drv->name, bitforce->device_id);
bitforce->nonce_range = false;
bitforce->sleep_ms *= 5;
bitforce->kname = KNAME_WORK;
goto re_send;
}
applog(LOG_ERR, "%s%i: Error: Send work reports: %s",
bitforce->drv->name, bitforce->device_id, buf);
return false;
}
sprintf((char *)ob, ">>>>>>>>");
memcpy(ob + 8, work->midstate, 32);
memcpy(ob + 8 + 32, work->data + 64, 12);
if (!bitforce->nonce_range) {
sprintf((char *)ob + 8 + 32 + 12, ">>>>>>>>");
work->blk.nonce = bitforce->nonces = 0xffffffff;
len = 60;
} else {
uint32_t *nonce;
nonce = (uint32_t *)(ob + 8 + 32 + 12);
*nonce = htobe32(work->blk.nonce);
nonce = (uint32_t *)(ob + 8 + 32 + 12 + 4);
/* Split work up into 1/5th nonce ranges */
bitforce->nonces = 0x33333332;
*nonce = htobe32(work->blk.nonce + bitforce->nonces);
work->blk.nonce += bitforce->nonces + 1;
sprintf((char *)ob + 8 + 32 + 12 + 8, ">>>>>>>>");
len = 68;
}
if ((err = usb_write(bitforce, (char *)ob, len, &amount, C_SENDWORK)) < 0 || amount != len) {
mutex_unlock(&bitforce->device_mutex);
applog(LOG_ERR, "%s%i: send work failed (%d:%d)",
bitforce->drv->name, bitforce->device_id, amount, err);
return false;
}
if ((err = usb_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_SENDWORKSTATUS)) < 0) {
mutex_unlock(&bitforce->device_mutex);
applog(LOG_ERR, "%s%d: read send work status failed (%d:%d)",
bitforce->drv->name, bitforce->device_id, amount, err);
return false;
}
mutex_unlock(&bitforce->device_mutex);
if (opt_debug) {
s = bin2hex(ob + 8, 44);
applog(LOG_DEBUG, "%s%i: block data: %s",
bitforce->drv->name, bitforce->device_id, s);
free(s);
}
if (amount == 0 || !buf[0]) {
applog(LOG_ERR, "%s%i: Error: Send block data returned empty string/timed out",
bitforce->drv->name, bitforce->device_id);
return false;
}
if (unlikely(strncasecmp(buf, "OK", 2))) {
applog(LOG_ERR, "%s%i: Error: Send block data reports: %s",
bitforce->drv->name, bitforce->device_id, buf);
return false;
}
cgtime(&bitforce->work_start_tv);
return true;
}
开发者ID:AxelWalsleben,项目名称:cgminer,代码行数:101,代码来源:driver-bitforce.c
示例20: hashratio_update_work
static void hashratio_update_work(struct cgpu_info *hashratio)
{
struct hashratio_info *info = hashratio->device_data;
struct thr_info *thr = hashratio->thr[0];
struct hashratio_pkg send_pkg;
uint32_t tmp, range, start;
struct work *work;
struct pool *pool;
applog(LOG_DEBUG, "hashratio: New stratum: restart: %d, update: %d",
thr->work_restart, thr->work_update);
thr->work_update = false;
thr->work_restart = false;
work = get_work(thr, thr->id); /* Make sure pool is ready */
discard_work(work); /* Don't leak memory */
pool = current_pool();
if (!pool->has_stratum)
quit(1, "hashratio: Miner Manager have to use stratum pool");
if (pool->coinbase_len > HRTO_P_COINBASE_SIZE)
quit(1, "hashratio: Miner Manager pool coinbase length have to less then %d", HRTO_P_COINBASE_SIZE);
if (pool->merkles > HRTO_P_MERKLES_COUNT)
quit(1, "hashratio: Miner Manager merkles have to less then %d", HRTO_P_MERKLES_COUNT);
info->pool_no = pool->pool_no;
cgtime(&info->last_stratum);
cg_rlock(&pool->data_lock);
info->pool_no = pool->pool_no;
copy_pool_stratum(info, pool);
hashratio_stratum_pkgs(hashratio, pool);
cg_runlock(&pool->data_lock);
/* Configure the parameter from outside */
memset(send_pkg.data, 0, HRTO_P_DATA_LEN);
// fan. We're not measuring temperature so set a safe but not max value
info->fan_pwm = HRTO_PWM_MAX * 2 / 3;
tmp = be32toh(info->fan_pwm);
memcpy(send_pkg.data, &tmp, 4);
// freq
tmp = be32toh(info->default_freq);
memcpy(send_pkg.data + 4, &tmp, 4);
applog(LOG_DEBUG, "set freq: %d", info->default_freq);
/* Configure the nonce2 offset and range */
range = 0xffffffff / (total_devices + 1);
start = range * (hashratio->device_id + 1);
tmp = be32toh(start);
memcpy(send_pkg.data + 8, &tmp, 4);
tmp = be32toh(range);
memcpy(send_pkg.data + 12, &tmp, 4);
/* Package the data */
hashratio_init_pkg(&send_pkg, HRTO_P_SET, 1, 1);
hashratio_send_pkgs(hashratio, &send_pkg);
}
开发者ID:60E,项目名称:cgminer,代码行数:61,代码来源:driver-hashratio.c
注:本文中的cgtime函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论