parent
f681f3dd60
commit
e820b88e0f
25
main.go
25
main.go
|
@ -41,7 +41,31 @@ func setMaxProcs() {
|
|||
}
|
||||
}
|
||||
|
||||
func broadcastTempeture(sender <-chan float64, handler util.Handler, receivers ...<-chan float64) {
|
||||
defer handler.DecreaseWait()
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
handler.NotifyError(err.(error))
|
||||
}
|
||||
}()
|
||||
for {
|
||||
select {
|
||||
case tempeture := <-sender:
|
||||
for _, receiver := range receivers {
|
||||
select {
|
||||
case receiver <- tempeture:
|
||||
default:
|
||||
log.Warn("Some Tempeture consumer blocked!")
|
||||
}
|
||||
}
|
||||
case <-handler.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
func main() {
|
||||
|
||||
var (
|
||||
processorCount = processor.GetProcessorCount()
|
||||
processors []processor.Processor
|
||||
|
@ -64,7 +88,6 @@ func main() {
|
|||
handler.NotifyError(err)
|
||||
} else {
|
||||
processors = append(processors, info)
|
||||
handler.IncreaseWait()
|
||||
go info.StartMonitoring()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,18 +17,30 @@ import (
|
|||
)
|
||||
|
||||
type processor struct {
|
||||
handler util.Handler
|
||||
id int
|
||||
tempeturePath string
|
||||
tempeture float64
|
||||
tempetureChanged chan float64
|
||||
sampleDuration time.Duration
|
||||
fanController pid.Controller
|
||||
fanSpeed int
|
||||
fanMaxSpeed int
|
||||
fanMinSpeed int
|
||||
fanSpeedChanged chan int
|
||||
handler util.Handler
|
||||
id int
|
||||
tempeturePath string
|
||||
tempeture float64
|
||||
tempetureChanged chan TempetureInfo
|
||||
sampleDuration time.Duration
|
||||
fanController pid.Controller
|
||||
fanSpeed int
|
||||
fanMaxSpeed int
|
||||
fanMinSpeed int
|
||||
fanSpeedChanged chan FanspeedInfo
|
||||
}
|
||||
|
||||
type TempetureInfo struct {
|
||||
Id int
|
||||
Tempeture float64
|
||||
}
|
||||
|
||||
type FanspeedInfo struct {
|
||||
Id int
|
||||
FanSpeed int
|
||||
}
|
||||
type TempetureChanged = <-chan TempetureInfo
|
||||
type FanspeedChanged = <-chan FanspeedInfo
|
||||
type Processor interface {
|
||||
Id() int
|
||||
Tempeture() float64
|
||||
|
@ -36,8 +48,8 @@ type Processor interface {
|
|||
FanMaxSpeed() int
|
||||
FanMinSpeed() int
|
||||
StartMonitoring()
|
||||
TempetureNotifier() <-chan float64
|
||||
FanSpeedNotifier() <-chan int
|
||||
TempetureNotifier() TempetureChanged
|
||||
FanSpeedNotifier() FanspeedChanged
|
||||
getMaxTempetureOnProcessor(string) (float64)
|
||||
readTempeture(string, chan<- float64, *sync.WaitGroup)
|
||||
normalizeFanspeed(float64) (int)
|
||||
|
@ -86,27 +98,28 @@ func NewProcessorInfo(
|
|||
controller.SetWindupGuard(windupGuard)
|
||||
|
||||
return &processor{
|
||||
handler: handler,
|
||||
id: processorId,
|
||||
tempeturePath: matches[0],
|
||||
tempetureChanged: make(chan float64),
|
||||
sampleDuration: sampleDuration,
|
||||
fanController: controller,
|
||||
fanSpeedChanged: make(chan int),
|
||||
fanMaxSpeed: maxNoob,
|
||||
fanMinSpeed: minNoob,
|
||||
handler: handler,
|
||||
id: processorId,
|
||||
tempeturePath: matches[0],
|
||||
tempetureChanged: make(chan TempetureInfo),
|
||||
sampleDuration: sampleDuration,
|
||||
fanController: controller,
|
||||
fanSpeedChanged: make(chan FanspeedInfo),
|
||||
fanMaxSpeed: maxNoob,
|
||||
fanMinSpeed: minNoob,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
func (p *processor) Id() int { return p.id }
|
||||
func (p *processor) Tempeture() float64 { return p.tempeture }
|
||||
func (p *processor) FanSpeed() int { return p.fanSpeed }
|
||||
func (p *processor) FanMaxSpeed() int { return p.fanMaxSpeed }
|
||||
func (p *processor) FanMinSpeed() int { return p.fanMinSpeed }
|
||||
func (p *processor) TempetureNotifier() <-chan float64 { return p.tempetureChanged }
|
||||
func (p *processor) FanSpeedNotifier() <-chan int { return p.fanSpeedChanged }
|
||||
func (p *processor) Id() int { return p.id }
|
||||
func (p *processor) Tempeture() float64 { return p.tempeture }
|
||||
func (p *processor) FanSpeed() int { return p.fanSpeed }
|
||||
func (p *processor) FanMaxSpeed() int { return p.fanMaxSpeed }
|
||||
func (p *processor) FanMinSpeed() int { return p.fanMinSpeed }
|
||||
func (p *processor) TempetureNotifier() TempetureChanged { return p.tempetureChanged }
|
||||
func (p *processor) FanSpeedNotifier() FanspeedChanged { return p.fanSpeedChanged }
|
||||
|
||||
func (p *processor) StartMonitoring() {
|
||||
p.handler.IncreaseWait()
|
||||
defer p.handler.DecreaseWait()
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
|
@ -131,13 +144,19 @@ func (p *processor) StartMonitoring() {
|
|||
|
||||
highestTemp = p.getMaxTempetureOnProcessor(tempeturePathGlob)
|
||||
if highestTemp != p.tempeture {
|
||||
p.tempetureChanged <- highestTemp
|
||||
p.tempetureChanged <- TempetureInfo{
|
||||
Id: p.id,
|
||||
Tempeture: highestTemp,
|
||||
}
|
||||
p.tempeture = highestTemp
|
||||
}
|
||||
|
||||
fanspeed = p.normalizeFanspeed(p.fanController.Update(highestTemp))
|
||||
if fanspeed != p.fanSpeed {
|
||||
p.fanSpeedChanged <- fanspeed
|
||||
p.fanSpeedChanged <- FanspeedInfo{
|
||||
Id:p.id,
|
||||
FanSpeed:fanspeed,
|
||||
}
|
||||
p.fanSpeed = fanspeed
|
||||
}
|
||||
|
||||
|
|
|
@ -1,39 +1,49 @@
|
|||
package speed_ctrl
|
||||
package processor
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"amuz.es/src/infra/cpu_ctrl/daemon"
|
||||
"amuz.es/src/infra/cpu_ctrl/logger"
|
||||
"amuz.es/src/infra/cpu_ctrl/processor"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"amuz.es/src/infra/cpu_ctrl/pid"
|
||||
"amuz.es/src/infra/cpu_ctrl/util"
|
||||
"time"
|
||||
"golang.org/x/tools/go/gcimporter15/testdata"
|
||||
)
|
||||
|
||||
var (
|
||||
log = logger.NewLogger("speed_ctrl")
|
||||
)
|
||||
type fanControl struct {
|
||||
processorCount int
|
||||
handler util.Handler
|
||||
fanSpeedConsumer chan FanspeedInfo
|
||||
}
|
||||
|
||||
type FanControl interface {
|
||||
}
|
||||
|
||||
func NewFanControl(processorCount int, handler util.Handler) FanControl {
|
||||
return &fanControl{
|
||||
processorCount: processorCount,
|
||||
handler: handler,
|
||||
fanSpeedConsumer: make(chan ),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *fanControl) StartControl() {
|
||||
c.handler.IncreaseWait()
|
||||
defer c.handler.DecreaseWait()
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
c.handler.NotifyError(err.(error))
|
||||
}
|
||||
}()
|
||||
|
||||
defer close(c.fanSpeedConsumer)
|
||||
ticker := time.Tick(p.sampleDuration)
|
||||
|
||||
}
|
||||
func TempetureControl(
|
||||
handler util.Handler,
|
||||
processors []processor.Processor,
|
||||
) {
|
||||
defer handler.DecreaseWait()
|
||||
var (
|
||||
P, I, D = 1.5, 0.4, 2.0
|
||||
SetPoint = 38.0
|
||||
SampleTime = time.Second
|
||||
maxNoob, minNoob = 0x64, 0x4
|
||||
WindupGuard = float64(maxNoob - minNoob)
|
||||
)
|
||||
|
||||
noobs := make([]int, processorCount)
|
||||
|
Loading…
Reference in New Issue