本文整理汇总了C++中cgtime函数的典型用法代码示例。如果您正苦于以下问题:C++ cgtime函数的具体用法?C++ cgtime怎么用?C++ cgtime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cgtime函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
//.........这里部分代码省略.........