mirror of
https://github.com/cryptonote-social/csminer.git
synced 2024-09-11 05:35:23 +03:00
support for dynamically adjusting the number of threads
This commit is contained in:
parent
ab044e4287
commit
6f7d915d5f
@ -21,7 +21,7 @@ const (
|
||||
|
||||
var (
|
||||
saver = flag.Bool("saver", true, "run only when screen is locked")
|
||||
threads = flag.Int("threads", 1, "number of threads")
|
||||
t = flag.Int("threads", 1, "number of threads")
|
||||
uname = flag.String("user", DONATE_USERNAME, "your pool username from https://cryptonote.social/xmr")
|
||||
rigid = flag.String("rigid", "csminer", "your rig id")
|
||||
tls = flag.Bool("tls", false, "whether to use TLS when connecting to the pool")
|
||||
@ -94,8 +94,9 @@ func MultiMain(s ScreenStater, agent string) {
|
||||
if *saver {
|
||||
fmt.Printf("\nNOTE: Mining only when screen is locked. Specify -saver=false to mine always.\n")
|
||||
}
|
||||
if *threads == 1 {
|
||||
if *t == 1 {
|
||||
fmt.Printf("\nMining with only one thread. Specify -threads=X to use more.\n")
|
||||
fmt.Printf("Or use the [i] keyboard command to add threads dynamically.\n")
|
||||
}
|
||||
if hr1 != -1 {
|
||||
fmt.Printf("\nMining will be paused between the hours of %v:00 and %v:00.\n", hr1, hr2)
|
||||
@ -105,9 +106,9 @@ func MultiMain(s ScreenStater, agent string) {
|
||||
|
||||
fmt.Println("\n==== Status/Debug output follows ====")
|
||||
crylog.Info("Miner username:", *uname)
|
||||
crylog.Info("Threads:", *threads)
|
||||
crylog.Info("Threads:", *t)
|
||||
|
||||
if Mine(s, *threads, *uname, *rigid, *saver, hr1, hr2, *startDiff, *tls, *config, agent) != nil {
|
||||
if Mine(s, *t, *uname, *rigid, *saver, hr1, hr2, *startDiff, *tls, *config, agent) != nil {
|
||||
crylog.Error("Miner failed:", err)
|
||||
}
|
||||
}
|
||||
|
54
miner.go
54
miner.go
@ -46,6 +46,8 @@ var (
|
||||
screenIdle int32 // only mine when this is > 0
|
||||
batteryPower int32 // only mine when this is > 0
|
||||
manualMinerToggle int32 // whether paused mining has been manually overridden
|
||||
|
||||
threads int
|
||||
)
|
||||
|
||||
const (
|
||||
@ -58,12 +60,14 @@ const (
|
||||
BATTERY_POWER = 2
|
||||
AC_POWER = 3
|
||||
|
||||
SCREEN_IDLE_POKE = 0
|
||||
SCREEN_ON_POKE = 1
|
||||
BATTERY_POWER_POKE = 2
|
||||
AC_POWER_POKE = 3
|
||||
PRINT_STATS_POKE = 4
|
||||
ENTER_HIT_POKE = 5
|
||||
SCREEN_IDLE_POKE = 0
|
||||
SCREEN_ON_POKE = 1
|
||||
BATTERY_POWER_POKE = 2
|
||||
AC_POWER_POKE = 3
|
||||
PRINT_STATS_POKE = 4
|
||||
ENTER_HIT_POKE = 5
|
||||
INCREASE_THREADS_POKE = 6
|
||||
DECREASE_THREADS_POKE = 7
|
||||
)
|
||||
|
||||
type ScreenState int
|
||||
@ -75,9 +79,10 @@ type ScreenStater interface {
|
||||
}
|
||||
|
||||
func Mine(
|
||||
s ScreenStater, threads int, uname, rigid string, saver bool,
|
||||
s ScreenStater, t int, uname, rigid string, saver bool,
|
||||
excludeHrStart int, excludeHrEnd int, startDiff int,
|
||||
useTLS bool, config string, agent string) error {
|
||||
threads = t
|
||||
if useTLS {
|
||||
cl = client.NewClient("cryptonote.social:5556", agent)
|
||||
} else {
|
||||
@ -336,6 +341,7 @@ func printKeyboardCommands() {
|
||||
crylog.Info("Keyboard commands:")
|
||||
crylog.Info(" s: print miner stats")
|
||||
crylog.Info(" p: print pool-side user stats")
|
||||
crylog.Info(" i/d: increase/decrease number of threads by 1")
|
||||
crylog.Info(" q: quit")
|
||||
crylog.Info(" <enter>: override a paused miner")
|
||||
}
|
||||
@ -346,6 +352,10 @@ func startKeyboardScanning(uname string) {
|
||||
for scanner.Scan() {
|
||||
b := scanner.Text()
|
||||
switch b {
|
||||
case "i":
|
||||
pokeJobDispatcher(INCREASE_THREADS_POKE)
|
||||
case "d":
|
||||
pokeJobDispatcher(DECREASE_THREADS_POKE)
|
||||
case "h", "s":
|
||||
pokeSuccess := pokeJobDispatcher(PRINT_STATS_POKE)
|
||||
if !pokeSuccess {
|
||||
@ -353,8 +363,8 @@ func startKeyboardScanning(uname string) {
|
||||
// still be safe to print stats.
|
||||
printStats(false)
|
||||
}
|
||||
case "q":
|
||||
crylog.Info("quitting due to q key command")
|
||||
case "q", "quit", "exit":
|
||||
crylog.Info("quitting due to keyboard command")
|
||||
os.Exit(0)
|
||||
case "?", "help":
|
||||
printKeyboardCommands()
|
||||
@ -608,6 +618,32 @@ func handlePoke(wasMining bool, poke int, excludeHrStart, excludeHrEnd int) int
|
||||
// stats for accuracy, so just trigger a fall-through and main loop will sync+dump stats.
|
||||
return USE_CACHED
|
||||
}
|
||||
if poke == INCREASE_THREADS_POKE {
|
||||
atomic.StoreUint32(&stopper, 1)
|
||||
wg.Wait()
|
||||
t := rx.AddThread()
|
||||
if t < 0 {
|
||||
crylog.Error("Failed to add another thread")
|
||||
return USE_CACHED
|
||||
}
|
||||
threads = t
|
||||
crylog.Info("Increased # of threads to:", threads)
|
||||
resetRecentStats()
|
||||
return USE_CACHED
|
||||
}
|
||||
if poke == DECREASE_THREADS_POKE {
|
||||
atomic.StoreUint32(&stopper, 1)
|
||||
wg.Wait()
|
||||
t := rx.RemoveThread()
|
||||
if t < 0 {
|
||||
crylog.Error("Failed to decrease threads")
|
||||
return USE_CACHED
|
||||
}
|
||||
threads = t
|
||||
crylog.Info("Decreased # of threads to:", threads)
|
||||
resetRecentStats()
|
||||
return USE_CACHED
|
||||
}
|
||||
isMiningNow := miningActive(excludeHrStart, excludeHrEnd)
|
||||
if wasMining != isMiningNow {
|
||||
// mining state was toggled so fall through using last received job which will
|
||||
|
12
rx/rx.go
12
rx/rx.go
@ -42,3 +42,15 @@ func HashUntil(blob []byte, difficulty uint64, thread int, hash []byte, nonce []
|
||||
(*C.uint32_t)(unsafe.Pointer(stopper)))
|
||||
return int64(res)
|
||||
}
|
||||
|
||||
// only call when all existing threads are stopped
|
||||
func AddThread() int {
|
||||
res := C.rx_add_thread()
|
||||
return int(res)
|
||||
}
|
||||
|
||||
// only call when all existing threads are stopped
|
||||
func RemoveThread() int {
|
||||
res := C.rx_remove_thread()
|
||||
return int(res)
|
||||
}
|
||||
|
@ -144,7 +144,6 @@ func (cl *Client) Connect(uname, pw, rigid string, useTLS bool) error {
|
||||
crylog.Error("Didn't get job result from login response:", response.Error)
|
||||
return errors.New(STRATUM_SERVER_ERROR + response.Error.Message)
|
||||
}
|
||||
crylog.Info("login response:", response)
|
||||
cl.firstJob = response.Result.Job
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user