Merge https://github.com/geekmug/cgminer into gitmug
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
diff --git a/main.c b/main.c
index 1596949..1453dbc 100644
--- a/main.c
+++ b/main.c
@@ -82,7 +82,7 @@ static inline void affine_to_cpu(int id, int cpu)
{
}
#endif
-
+
enum workio_commands {
WC_GET_WORK,
WC_SUBMIT_WORK,
@@ -675,7 +675,7 @@ static double bench_algo_stage2(
);
// Create and init a chunked of shared memory
- HANDLE map_handle = CreateFileMapping(
+ HANDLE map_handle = CreateFileMapping(
INVALID_HANDLE_VALUE, // use paging file
NULL, // default security attributes
PAGE_READWRITE, // read/write access
@@ -688,7 +688,7 @@ static double bench_algo_stage2(
exit(1);
}
- void *shared_mem = MapViewOfFile(
+ void *shared_mem = MapViewOfFile(
map_handle, // object to map view of
FILE_MAP_WRITE, // read/write access
0, // high offset: map from
@@ -731,7 +731,7 @@ static double bench_algo_stage2(
FALSE, // Set handle inheritance to FALSE
DEBUG_ONLY_THIS_PROCESS,// We're going to debug the child
NULL, // Use parent's environment block
- NULL, // Use parent's starting directory
+ NULL, // Use parent's starting directory
&startup_info, // Pointer to STARTUPINFO structure
&process_info // Pointer to PROCESS_INFORMATION structure
);
@@ -787,8 +787,8 @@ static double bench_algo_stage2(
// Reap return value and cleanup
CopyMemory(&rate, shared_mem, sizeof(rate));
- (void)UnmapViewOfFile(shared_mem);
- (void)CloseHandle(map_handle);
+ (void)UnmapViewOfFile(shared_mem);
+ (void)CloseHandle(map_handle);
#else
@@ -2367,7 +2367,7 @@ static void disable_curses(void)
HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
COORD coord;
-
+
if (GetConsoleScreenBufferInfo(hout, &csbi)) {
coord.X = 0;
coord.Y = csbi.dwSize.Y - 1;
@@ -3487,7 +3487,6 @@ static void hashmeter(int thr_id, struct timeval *diff,
static double local_mhashes_done = 0;
static double rolling = 0;
double local_mhashes = (double)hashes_done / 1000000.0;
- struct cgpu_info *cgpu = thr_info[thr_id].cgpu;
bool showlog = false;
/* Update the last time this thread reported in */
@@ -3497,12 +3496,13 @@ static void hashmeter(int thr_id, struct timeval *diff,
/* Don't bother calculating anything if we're not displaying it */
if (opt_realquiet || !opt_log_interval)
return;
-
+
secs = (double)diff->tv_sec + ((double)diff->tv_usec / 1000000.0);
/* So we can call hashmeter from a non worker thread */
if (thr_id >= 0) {
struct thr_info *thr = &thr_info[thr_id];
+ struct cgpu_info *cgpu = thr_info[thr_id].cgpu;
double thread_rolling = 0.0;
int i;
@@ -4218,7 +4218,7 @@ static cl_int queue_phatk_kernel(_clState *clState, dev_blk_ctx *blk)
status |= clSetKernelArg(*kernel, num++, sizeof(uint), (void *)&blk->ctx_f);
status |= clSetKernelArg(*kernel, num++, sizeof(uint), (void *)&blk->ctx_g);
status |= clSetKernelArg(*kernel, num++, sizeof(uint), (void *)&blk->ctx_h);
-
+
status |= clSetKernelArg(*kernel, num++, sizeof(uint), (void *)&blk->cty_b);
status |= clSetKernelArg(*kernel, num++, sizeof(uint), (void *)&blk->cty_c);
status |= clSetKernelArg(*kernel, num++, sizeof(uint), (void *)&blk->cty_d);
@@ -4536,7 +4536,7 @@ static void *longpoll_thread(void *userdata)
lp_url = hdr_path;
hdr_path = NULL;
}
-
+
/* absolute path, on current server */
else {
copy_start = (*hdr_path == '/') ? (hdr_path + 1) : hdr_path;
@@ -5259,6 +5259,8 @@ int main (int argc, char *argv[])
init_max_name_len();
handler.sa_handler = &sighandler;
+ handler.sa_flags = 0;
+ sigemptyset(&handler.sa_mask);
sigaction(SIGTERM, &handler, &termhandler);
sigaction(SIGINT, &handler, &inthandler);
@@ -5359,7 +5361,7 @@ int main (int argc, char *argv[])
#if defined(WIN32)
char unique_name[64];
if (GetEnvironmentVariable("CGMINER_SHARED_MEM", unique_name, 32)) {
- HANDLE map_handle = CreateFileMapping(
+ HANDLE map_handle = CreateFileMapping(
INVALID_HANDLE_VALUE, // use paging file
NULL, // default security attributes
PAGE_READWRITE, // read/write access
@@ -5368,18 +5370,18 @@ int main (int argc, char *argv[])
unique_name // name of map object
);
if (NULL!=map_handle) {
- void *shared_mem = MapViewOfFile(
+ void *shared_mem = MapViewOfFile(
map_handle, // object to map view of
FILE_MAP_WRITE, // read/write access
0, // high offset: map from
0, // low offset: beginning
0 // default: map entire file
);
- if (NULL!=shared_mem)
+ if (NULL!=shared_mem)
CopyMemory(shared_mem, &rate, sizeof(rate));
- (void)UnmapViewOfFile(shared_mem);
+ (void)UnmapViewOfFile(shared_mem);
}
- (void)CloseHandle(map_handle);
+ (void)CloseHandle(map_handle);
}
#endif
}
@@ -5396,6 +5398,7 @@ int main (int argc, char *argv[])
} else
chosen_kernel = KL_NONE;
+#ifdef HAVE_OPENCL
gpu_threads = nDevs * opt_g_threads;
if (total_devices) {
if (total_devices > nDevs)
@@ -5418,6 +5421,9 @@ int main (int argc, char *argv[])
gpu_devices[i] = true;
total_devices = nDevs;
}
+#else
+ gpu_threads = 0;
+#endif
if (!gpu_threads && !forced_n_threads) {
/* Maybe they turned GPU off; restore default CPU threads. */
@@ -5456,7 +5462,7 @@ int main (int argc, char *argv[])
quit(1, "Failed to malloc userpass");
sprintf(pool->rpc_userpass, "%s:%s", pool->rpc_user, pool->rpc_pass);
} else {
- pool->rpc_user = malloc(strlen(pool->rpc_userpass));
+ pool->rpc_user = malloc(strlen(pool->rpc_userpass) + 1);
if (!pool->rpc_user)
quit(1, "Failed to malloc user");
strcpy(pool->rpc_user, pool->rpc_userpass);
@@ -5498,7 +5504,7 @@ int main (int argc, char *argv[])
quit(1, "Failed to tq_new");
/* start work I/O thread */
- if (thr_info_create(thr, NULL, workio_thread, thr))
+ if (thr_info_create(thr, NULL, workio_thread, thr))
quit(1, "workio thread create failed");
/* init longpoll thread info */
diff --git a/miner.h b/miner.h
index 472e39a..c21f189 100644
--- a/miner.h
+++ b/miner.h
@@ -81,7 +81,9 @@ void *alloca (size_t);
#endif
#if !defined(WIN32) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
-#define WANT_BUILTIN_BSWAP
+#define bswap_16 __builtin_bswap16
+#define bswap_32 __builtin_bswap32
+#define bswap_64 __builtin_bswap64
#else
#if HAVE_BYTESWAP_H
#include <byteswap.h>
@@ -99,7 +101,7 @@ void *alloca (size_t);
#define bswap_32(value) \
(((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
(uint32_t)bswap_16((uint16_t)((value) >> 16)))
-
+
#define bswap_64(value) \
(((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
<< 32) | \
@@ -244,11 +246,7 @@ extern void thr_info_cancel(struct thr_info *thr);
static inline uint32_t swab32(uint32_t v)
{
-#ifdef WANT_BUILTIN_BSWAP
- return __builtin_bswap32(v);
-#else
return bswap_32(v);
-#endif
}
static inline void swap256(void *dest_p, const void *src_p)