Compare commits

...

2 Commits

Author SHA1 Message Date
nisdas
0f862a550e mock it out 2022-08-19 19:03:39 +08:00
nisdas
e3420ed74e remove sigill channel 2022-08-19 18:48:21 +08:00

View File

@@ -21,12 +21,10 @@ package features
import (
"os"
"os/signal"
"sync"
"syscall"
"time"
"github.com/prysmaticlabs/gohashtree"
"github.com/prysmaticlabs/prysm/v3/cmd"
"github.com/prysmaticlabs/prysm/v3/config/params"
"github.com/sirupsen/logrus"
@@ -211,22 +209,7 @@ func ConfigureBeaconChain(ctx *cli.Context) error {
if ctx.Bool(disableVecHTR.Name) {
logEnabled(disableVecHTR)
} else {
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGILL)
defer signal.Stop(sigc)
buffer := make([][32]byte, 2)
err := gohashtree.Hash(buffer, buffer)
if err != nil {
log.Error("could not test if gohashtree is supported")
} else {
t := time.NewTimer(time.Millisecond * 100)
select {
case <-sigc:
log.Error("gohashtree is not supported in this CPU")
case <-t.C:
cfg.EnableVectorizedHTR = true
}
}
applyVectorizedHTRConfig(cfg)
}
if ctx.Bool(disableForkChoiceDoublyLinkedTree.Name) {
logEnabled(disableForkChoiceDoublyLinkedTree)
@@ -316,3 +299,28 @@ func logDisabled(flag cli.DocGenerationFlag) {
}
log.WithField(name, flag.GetUsage()).Warn(disabledFeatureFlag)
}
func applyVectorizedHTRConfig(cfg *Flags) (appliedCfg *Flags) {
defer func() {
if x := recover(); x != nil {
log.Error("gohashtree is not supported in this CPU")
}
}()
appliedCfg = cfg
buffer := make([][32]byte, 2)
err := mockSIGILL(buffer, buffer)
if err != nil {
log.WithError(err).Error("could not test if gohashtree is supported")
return
}
appliedCfg.EnableVectorizedHTR = true
return
}
func mockSIGILL(_, _ [][32]byte) error {
p, err := os.FindProcess(os.Getpid())
if err != nil {
return err
}
return p.Signal(syscall.SIGILL)
}