Browse Source

Algorithm Switcher Update

Updated Algorithm switcher to change on pool rather than on algorithm.
This way if, for example, 2 pools use the same algorithm but different
GPU settings, the settings will be applied when changing pool.

Additionally:
* Included a "common" algorithm type in API pool/profile listing. For
example using "marucoin-mod" will return "X13", "darkcoin-mod" will
return "X11", scrypt + nfactor != 10 will return "NScrypt", etc...

* Added "kernel" config option to be backwards compatible with other
miners' configs.

* Added a few algorithm aliases: x11mod -> darkcoin-mod, x13mod ->
marucoin-mod...

* New config keyword: "includes", which holds an array of include files.
This is to counter the JSON limitation not allowing multiple values with
the same name, thus preventing inclusion of multiple files.
djm34
ystarnaud 11 years ago
parent
commit
3ae5f97b94
  1. 69
      algorithm.c
  2. 16
      algorithm.h
  3. 12
      api.c
  4. 28
      config_parser.c
  5. 1
      driver-opencl.c
  6. 37
      miner.h
  7. 819
      sgminer.c

69
algorithm.c

@ -31,6 +31,21 @@ @@ -31,6 +31,21 @@
#include <inttypes.h>
#include <string.h>
const char *algorithm_type_str[] = {
"Unknown",
"Scrypt",
"NScrypt",
"X11",
"X13",
"Keccak",
"Quarkcoin",
"Twecoin",
"Fugue256",
"NIST"
};
void sha256(const unsigned char *message, unsigned int len, unsigned char *digest)
{
sph_sha256_context ctx_sha2;
@ -308,6 +323,7 @@ static cl_int queue_talkcoin_mod_kernel(struct __clState *clState, struct _dev_b @@ -308,6 +323,7 @@ static cl_int queue_talkcoin_mod_kernel(struct __clState *clState, struct _dev_b
typedef struct _algorithm_settings_t {
const char *name; /* Human-readable identifier */
algorithm_type_t type; //common algorithm type
double diff_multiplier1;
double diff_multiplier2;
double share_diff_multiplier;
@ -329,7 +345,7 @@ typedef struct _algorithm_settings_t { @@ -329,7 +345,7 @@ typedef struct _algorithm_settings_t {
static algorithm_settings_t algos[] = {
// kernels starting from this will have difficulty calculated by using litecoin algorithm
#define A_SCRYPT(a) \
{ a, 1, 65536, 65536, 0, 0, 0xFF, 0x0000ffff00000000ULL, 0xFFFFFFFFULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, scrypt_regenhash, queue_scrypt_kernel, gen_hash, append_scrypt_compiler_options}
{ a, ALGO_SCRYPT, 1, 65536, 65536, 0, 0, 0xFF, 0x0000ffff00000000ULL, 0xFFFFFFFFULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, scrypt_regenhash, queue_scrypt_kernel, gen_hash, append_scrypt_compiler_options}
A_SCRYPT( "ckolivas" ),
A_SCRYPT( "alexkarnew" ),
A_SCRYPT( "alexkarnold" ),
@ -340,7 +356,7 @@ static algorithm_settings_t algos[] = { @@ -340,7 +356,7 @@ static algorithm_settings_t algos[] = {
// kernels starting from this will have difficulty calculated by using quarkcoin algorithm
#define A_QUARK(a, b) \
{ a, 256, 256, 256, 0, 0, 0xFF, 0x000000ffff000000ULL, 0xFFFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, queue_sph_kernel, gen_hash, NULL}
{ a, ALGO_QUARK, 256, 256, 256, 0, 0, 0xFF, 0x000000ffff000000ULL, 0xFFFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, queue_sph_kernel, gen_hash, NULL}
A_QUARK( "quarkcoin", quarkcoin_regenhash),
A_QUARK( "qubitcoin", qubitcoin_regenhash),
A_QUARK( "animecoin", animecoin_regenhash),
@ -349,31 +365,31 @@ static algorithm_settings_t algos[] = { @@ -349,31 +365,31 @@ static algorithm_settings_t algos[] = {
// kernels starting from this will have difficulty calculated by using bitcoin algorithm
#define A_DARK(a, b) \
{ a, 1, 1, 1, 0, 0, 0xFF, 0x00000000ffff0000ULL, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, queue_sph_kernel, gen_hash, NULL}
{ a, ALGO_X11, 1, 1, 1, 0, 0, 0xFF, 0x00000000ffff0000ULL, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, queue_sph_kernel, gen_hash, NULL}
A_DARK( "darkcoin", darkcoin_regenhash),
A_DARK( "inkcoin", inkcoin_regenhash),
A_DARK( "myriadcoin-groestl", myriadcoin_groestl_regenhash),
#undef A_DARK
{ "twecoin", 1, 1, 1, 0, 0, 0xFF, 0x00000000ffff0000ULL, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, twecoin_regenhash, queue_sph_kernel, sha256, NULL},
{ "maxcoin", 1, 256, 1, 4, 15, 0x0F, 0x00000000ffff0000ULL, 0xFFFFULL, 0x000000ffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, maxcoin_regenhash, queue_maxcoin_kernel, sha256, NULL},
{ "darkcoin-mod", 1, 1, 1, 0, 0, 0xFF, 0x00000000ffff0000ULL, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, darkcoin_regenhash, queue_darkcoin_mod_kernel, gen_hash, NULL},
{ "twecoin", ALGO_TWE, 1, 1, 1, 0, 0, 0xFF, 0x00000000ffff0000ULL, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, twecoin_regenhash, queue_sph_kernel, sha256, NULL},
{ "maxcoin", ALGO_KECCAK, 1, 256, 1, 4, 15, 0x0F, 0x00000000ffff0000ULL, 0xFFFFULL, 0x000000ffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, maxcoin_regenhash, queue_maxcoin_kernel, sha256, NULL},
{ "darkcoin-mod", ALGO_X11, 1, 1, 1, 0, 0, 0xFF, 0x00000000ffff0000ULL, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, darkcoin_regenhash, queue_darkcoin_mod_kernel, gen_hash, NULL},
{ "marucoin", 1, 1, 1, 0, 0, 0xFF, 0x00000000ffff0000ULL, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, marucoin_regenhash, queue_sph_kernel, gen_hash, append_hamsi_compiler_options},
{ "marucoin-mod", 1, 1, 1, 0, 0, 0xFF, 0x00000000ffff0000ULL, 0xFFFFULL, 0x0000ffffUL, 12, 8 * 16 * 4194304, 0, marucoin_regenhash, queue_marucoin_mod_kernel, gen_hash, append_hamsi_compiler_options},
{ "marucoin-modold", 1, 1, 1, 0, 0, 0xFF, 0x00000000ffff0000ULL, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, marucoin_regenhash, queue_marucoin_mod_old_kernel, gen_hash, append_hamsi_compiler_options},
{ "marucoin", ALGO_X13, 1, 1, 1, 0, 0, 0xFF, 0x00000000ffff0000ULL, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, marucoin_regenhash, queue_sph_kernel, gen_hash, append_hamsi_compiler_options},
{ "marucoin-mod", ALGO_X13, 1, 1, 1, 0, 0, 0xFF, 0x00000000ffff0000ULL, 0xFFFFULL, 0x0000ffffUL, 12, 8 * 16 * 4194304, 0, marucoin_regenhash, queue_marucoin_mod_kernel, gen_hash, append_hamsi_compiler_options},
{ "marucoin-modold", ALGO_X13, 1, 1, 1, 0, 0, 0xFF, 0x00000000ffff0000ULL, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, marucoin_regenhash, queue_marucoin_mod_old_kernel, gen_hash, append_hamsi_compiler_options},
{ "talkcoin-mod", 1, 1, 1, 0, 0, 0xFF, 0x00000000ffff0000ULL, 0xFFFFULL, 0x0000ffffUL, 4, 8 * 16 * 4194304, 0, talkcoin_regenhash, queue_talkcoin_mod_kernel, gen_hash, NULL},
{ "talkcoin-mod", ALGO_NIST, 1, 1, 1, 0, 0, 0xFF, 0x00000000ffff0000ULL, 0xFFFFULL, 0x0000ffffUL, 4, 8 * 16 * 4194304, 0, talkcoin_regenhash, queue_talkcoin_mod_kernel, gen_hash, NULL},
// kernels starting from this will have difficulty calculated by using fuguecoin algorithm
#define A_FUGUE(a, b) \
{ a, 1, 256, 256, 0, 0, 0xFF, 0x00000000ffff0000ULL, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, queue_sph_kernel, sha256, NULL}
{ a, ALGO_FUGUE, 1, 256, 256, 0, 0, 0xFF, 0x00000000ffff0000ULL, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, queue_sph_kernel, sha256, NULL}
A_FUGUE( "fuguecoin", fuguecoin_regenhash),
A_FUGUE( "groestlcoin", groestlcoin_regenhash),
#undef A_FUGUE
// Terminator (do not remove)
{ NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL}
{ NULL, ALGO_UNK, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL}
};
void copy_algorithm_settings(algorithm_t* dest, const char* algo)
@ -381,9 +397,12 @@ void copy_algorithm_settings(algorithm_t* dest, const char* algo) @@ -381,9 +397,12 @@ void copy_algorithm_settings(algorithm_t* dest, const char* algo)
algorithm_settings_t* src;
// Find algorithm settings and copy
for (src = algos; src->name; src++) {
if (strcmp(src->name, algo) == 0) {
for (src = algos; src->name; src++)
{
if (strcmp(src->name, algo) == 0)
{
strcpy(dest->name, src->name);
dest->type = src->type;
dest->diff_multiplier1 = src->diff_multiplier1;
dest->diff_multiplier2 = src->diff_multiplier2;
@ -406,7 +425,8 @@ void copy_algorithm_settings(algorithm_t* dest, const char* algo) @@ -406,7 +425,8 @@ void copy_algorithm_settings(algorithm_t* dest, const char* algo)
}
// if not found
if (src->name == NULL) {
if (src->name == NULL)
{
applog(LOG_WARNING, "Algorithm %s not found, using %s.", algo, algos->name);
copy_algorithm_settings(dest, algos->name);
}
@ -457,6 +477,25 @@ void set_algorithm_nfactor(algorithm_t* algo, const uint8_t nfactor) @@ -457,6 +477,25 @@ void set_algorithm_nfactor(algorithm_t* algo, const uint8_t nfactor)
{
algo->nfactor = nfactor;
algo->n = (1 << nfactor);
//adjust algo type accordingly
switch (algo->type)
{
case ALGO_SCRYPT:
//if nfactor isnt 10, switch to NSCRYPT
if(algo->nfactor != 10)
algo->type = ALGO_NSCRYPT;
break;
//nscrypt
case ALGO_NSCRYPT:
//if nfactor is 10, switch to SCRYPT
if(algo->nfactor == 10)
algo->type = ALGO_SCRYPT;
break;
//ignore rest
default:
break;
}
}
bool cmp_algorithm(algorithm_t* algo1, algorithm_t* algo2)

16
algorithm.h

@ -10,6 +10,21 @@ @@ -10,6 +10,21 @@
#include <inttypes.h>
#include <stdbool.h>
typedef enum {
ALGO_UNK,
ALGO_SCRYPT,
ALGO_NSCRYPT,
ALGO_X11,
ALGO_X13,
ALGO_KECCAK,
ALGO_QUARK,
ALGO_TWE,
ALGO_FUGUE,
ALGO_NIST
} algorithm_type_t;
extern const char *algorithm_type_str[];
extern void gen_hash(const unsigned char *data, unsigned int len, unsigned char *hash);
struct __clState;
@ -23,6 +38,7 @@ struct work; @@ -23,6 +38,7 @@ struct work;
*/
typedef struct _algorithm_t {
char name[20]; /* Human-readable identifier */
algorithm_type_t type; //algorithm type
uint32_t n; /* N (CPU/Memory tradeoff parameter) */
uint8_t nfactor; /* Factor of N above (n = 2^nfactor) */
double diff_multiplier1;

12
api.c

@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
#include "pool.h"
#include "util.h"
#include "pool.h"
#include "algorithm.h"
#include "config_parser.h"
@ -1602,8 +1603,14 @@ static void poolstatus(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m @@ -1602,8 +1603,14 @@ static void poolstatus(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
root = api_add_string(root, "Name", get_pool_name(pool), true);
mutex_unlock(&pool->stratum_lock);
root = api_add_escape(root, "URL", pool->rpc_url, false);
root = api_add_string(root, "Profile", pool->profile, false);
root = api_add_string(root, "Algorithm", pool->algorithm.name, false);
root = api_add_escape(root, "Profile", pool->profile, false);
root = api_add_escape(root, "Algorithm", pool->algorithm.name, false);
root = api_add_escape(root, "Algorithm Type", (char *)algorithm_type_str[pool->algorithm.type], false);
//show nfactor for nscrypt
if(pool->algorithm.type == ALGO_NSCRYPT)
root = api_add_int(root, "Algorithm NFactor", (int *)&(pool->algorithm.nfactor), false);
root = api_add_string(root, "Description", pool->description, false);
root = api_add_string(root, "Status", status, false);
root = api_add_int(root, "Priority", &(pool->prio), false);
@ -1620,6 +1627,7 @@ static void poolstatus(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m @@ -1620,6 +1627,7 @@ static void poolstatus(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
root = api_add_escape(root, "User", pool->rpc_user, false);
root = api_add_time(root, "Last Share Time", &(pool->last_share_time), false);
root = api_add_double(root, "Diff1 Shares", &(pool->diff1), false);
if (pool->rpc_proxy) {
root = api_add_const(root, "Proxy Type", proxytype(pool->rpc_proxytype), false);
root = api_add_escape(root, "Proxy", pool->rpc_proxy, false);

28
config_parser.c

@ -499,7 +499,8 @@ void parse_config_object(json_t *obj, const char *parentkey, bool fileconf, int @@ -499,7 +499,8 @@ void parse_config_object(json_t *obj, const char *parentkey, bool fileconf, int
{
//char *err = NULL;
const char *key;
json_t *val;
size_t idx;
json_t *val, *subval;
json_object_foreach(obj, key, val)
{
@ -509,6 +510,18 @@ void parse_config_object(json_t *obj, const char *parentkey, bool fileconf, int @@ -509,6 +510,18 @@ void parse_config_object(json_t *obj, const char *parentkey, bool fileconf, int
if(val && json_is_string(val))
load_config(json_string_value(val), parentkey, NULL);
}
//process includes - multi include
else if(!strcasecmp(key, "includes"))
{
if(val && json_is_array(val))
{
json_array_foreach(val, idx, subval)
{
if(subval && json_is_string(subval))
load_config(json_string_value(subval), parentkey, NULL);
}
}
}
else
parse_config(val, key, parentkey, fileconf, parent_iteration);
/*
@ -689,7 +702,7 @@ void load_default_profile() @@ -689,7 +702,7 @@ void load_default_profile()
// ... and copy settings
if(!empty_string(profile->algorithm.name))
set_algorithm(&default_profile.algorithm, profile->algorithm.name);
default_profile.algorithm = profile->algorithm;
if(!empty_string(profile->devices))
default_profile.devices = profile->devices;
@ -743,8 +756,10 @@ void apply_defaults() @@ -743,8 +756,10 @@ void apply_defaults()
set_algorithm(&default_profile.algorithm, "scrypt");
//by default all unless specified
if (empty_string(default_profile.devices))
if(empty_string(default_profile.devices))
default_profile.devices = strdup("all");
applog(LOG_DEBUG, "Default Devices = %s", default_profile.devices);
set_devices((char *)default_profile.devices);
//set raw intensity first
@ -1919,7 +1934,12 @@ void api_profile_list(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __ma @@ -1919,7 +1934,12 @@ void api_profile_list(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __ma
root = api_add_escape(root, "Name", profile->name, true);
root = api_add_bool(root, "IsDefault", &b, false);
root = api_add_escape(root, "Algorithm", isnull((char *)profile->algorithm.name, ""), true);
root = api_add_int(root, "NFactor", (int *)&profile->algorithm.nfactor, false);
root = api_add_escape(root, "Algorithm Type", (char *)algorithm_type_str[profile->algorithm.type], false);
//show nfactor for nscrypt
if(profile->algorithm.type == ALGO_NSCRYPT)
root = api_add_int(root, "Algorithm NFactor", (int *)&(profile->algorithm.nfactor), false);
root = api_add_escape(root, "LookupGap", isnull((char *)profile->lookup_gap, ""), true);
root = api_add_escape(root, "Devices", isnull((char *)profile->devices, ""), true);
root = api_add_escape(root, "Intensity", isnull((char *)profile->intensity, ""), true);

1
driver-opencl.c

@ -1320,6 +1320,7 @@ static bool opencl_thread_init(struct thr_info *thr) @@ -1320,6 +1320,7 @@ static bool opencl_thread_init(struct thr_info *thr)
static bool opencl_prepare_work(struct thr_info __maybe_unused *thr, struct work *work)
{
work->blk.work = work;
thr->pool_no = work->pool->pool_no;
return true;
}

37
miner.h

@ -321,9 +321,45 @@ struct gpu_adl { @@ -321,9 +321,45 @@ struct gpu_adl {
};
#endif
/***********************************
* Switcher stuff
****************************************/
#ifndef opt_isset
#define opt_isset(opt, val) (((opt & val) == val)?1:0)
#endif
#ifndef get_pool_setting
#define get_pool_setting(val, default_val) ((!empty_string(val))?val:((!empty_string(default_val))?default_val:""))
#endif
enum switcher_mode {
SWITCH_OFF,
SWITCH_ALGO,
SWITCH_POOL
};
extern int opt_switchmode;
enum switcher_options {
SWITCHER_APPLY_NONE = 0x00,
SWITCHER_APPLY_ALGO = 0x01,
SWITCHER_APPLY_DEVICE = 0x02,
SWITCHER_APPLY_GT = 0x04,
SWITCHER_APPLY_LG = 0x08,
SWITCHER_APPLY_RAWINT = 0x10,
SWITCHER_APPLY_XINT = 0x20,
SWITCHER_APPLY_INT = 0x40,
SWITCHER_APPLY_INT8 = 0x80,
SWITCHER_APPLY_SHADER = 0x100,
SWITCHER_APPLY_TC = 0x200,
SWITCHER_APPLY_WORKSIZE = 0x400,
SWITCHER_APPLY_GPU_ENGINE = 0x800,
SWITCHER_APPLY_GPU_MEMCLOCK = 0x1000,
SWITCHER_APPLY_GPU_FAN = 0x2000,
SWITCHER_APPLY_GPU_POWERTUNE = 0x4000,
SWITCHER_APPLY_GPU_VDDC = 0x8000,
SWITCHER_SOFT_RESET = 0x4000000,
SWITCHER_HARD_RESET = 0x8000000
};
enum gpu_adl_options {
APPLY_ENGINE = 1,
@ -572,6 +608,7 @@ struct thr_info { @@ -572,6 +608,7 @@ struct thr_info {
struct thread_q *q;
struct cgpu_info *cgpu;
void *cgpu_data;
int pool_no;
struct timeval last;
struct timeval sick;

819
sgminer.c

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save