Commit 39daea2b authored by Valentin Reis's avatar Valentin Reis
Browse files

[refactor] simplify/document configuration and manifest format.

parent ed4d1dd1
Pipeline #11766 passed with stages
in 4 minutes and 13 seconds
......@@ -31,6 +31,7 @@ pre-commit: hsnrm/pre-commit\
pynrm/pre-commit\
libnrm/pre-commit\
dhall-format\
resources\
examples\
shellcheck\
nixfmt\
......@@ -114,6 +115,7 @@ pynrm/nrm/schemas/downstreamEvent.json: resources
libnrm/src/nrm_messaging.h: resources
cp resources/nrm_messaging.h $@
.PHONY:resources
resources:
@nix-shell --pure -E '
let pkgs = import <nixpkgs> {};
......
......@@ -18,6 +18,7 @@ git clone https://xgitlab.cels.anl.gov/argo/hnrm.git
## Usage
### binaries
```
#daemon
nrmd --help
......@@ -26,23 +27,27 @@ nrm --help
```
### `nrmd` configuration / `nrm` manifests
`nrmd` configurations and `nrm` manifests can use any of YAML, JSON or Dhall.
JSON schemas (raw) and Dhall types (documented with comments, for now)
are available.
These two configuration formats are defined and documented using Dhall types.
Default values and examples are available in JSON/YAML/Dhall format.
when using JSON/YAML, relevant files are:
- default values: `resources/defauts/{nrmd,manifest}.json`
- examples: `examples/*/*.{json,yaml}`
when using Dhall,
when using Dhall, relevant files are:
- types: `hsnrm/hsnrm/dhall/types/{nrmd,manifest}.dhall`
- default values: `hsnrm/hsnrm/dhall/defaults/{nrmd,manifest}.dhall`
- examples: `examples/*/*.dhall`
when using JSON/YAML,
- default values: `resources/defauts/{nrmd,manifest}.json`
Example `nrmd` configurations and `nrm` manifests are available in the
`examples` folder in JSON,YAML and Dhall format.
The authoritative source of documentation for both the configuration format and
manifest files is contained in Dhall type definitions:
`hsnrm/hsnrm/dhall/types/{nrmd,manifest}.dhall`.
### APIs
JSON schema files for upstream and downstream APIs are available.
JSON schema files for upstream and downstream APIs are available:
- JSON/YAML schemas: `resources/schemas/{upstream-*,downstream}.json`
## Development
......@@ -51,4 +56,4 @@ JSON schema files for upstream and downstream APIs are available.
- running CI jobs locally: `make ci-<jobname>` or all jobs using `make ci`
(requires gitlab-runner)
- entering a development shell : `nix-shell`. The appropriate `shellHooks` are
in place for the `nrm` and `nrmd` aliases to be used on the CLI.
in place for the `nrm` and `nrmd` aliases to be used on the CLI.
......@@ -9,21 +9,7 @@ let t = ../types/manifest.dhall
in { name = "default"
, app =
{ slice = { cpus = +1, mems = +1 }
, scheduler = t.Scheduler.FIFO
, perfwrapper = None t.Perfwrapper
, powerCfg =
{ policy = < NoPowerPolicy | DDCM | DVFS | Combined >.NoPowerPolicy
, profile = False
, slowdown = +1
}
{ perfwrapper = None t.Perfwrapper
, instrumentation = None t.Instrumentation
}
, hwbind = False
, image =
None
{ path : Text
, imagetype : < Sif | Docker >
, binds : Optional (List Text)
}
}
......@@ -2,15 +2,9 @@ let t = ../types/nrmd.dhall
in { verbose = t.Verbosity.Error
, logfile = "/tmp/nrm.log"
, hwloc = "hwloc"
, perf = "perf"
, argo_perf_wrapper = "nrm-perfwrapper"
, argo_nodeos_config = "argo_nodeos_config"
, perfPath = "perf"
, perfwrapperPath = "nrm-perfwrapper"
, libnrmPath = None Text
, pmpi_lib = "pmpi_lib"
, singularity = False
, dummy = True
, nodeos = False
, downstreamCfg.downstreamBindAddress = "ipc:///tmp/nrm-downstream-event"
, upstreamCfg =
{ upstreamBindAddress = "*", pubPort = +2345, rpcPort = +3456 }
......@@ -19,7 +13,6 @@ in { verbose = t.Verbosity.Error
, raplActions = [ { microwatts = 1.0e8 }, { microwatts = 2.0e8 } ]
, referencePower.microwatts = 2.5e8
}
, hwmonCfg = { hwmonEnabled = True, hwmonPath = "/sys/class/hwmon" }
, controlCfg = t.ControlCfg.ControlOff
, passiveSensorFrequency.hertz = 1.0
, extraStaticPassiveSensors = [] : List t.SensorKV
......
......@@ -4,62 +4,38 @@
--
-- SPDX-License-Identifier: BSD-3-Clause
-- ******************************************************************************
let types = ./types.dhall
let Scheduler =
-- This type was imported from NRM1: feature not present (yet)
< FIFO | HPC | Other : Integer >
let types =
-- This import defines a few base types that are common to manifest and
-- configuration formats.
./types.dhall
let Perfwrapper =
-- Configuration for linux perf performance measurements.
-- Configuration for linux perf performance measurements. A fixed frequency
-- is provided, along with a tentative upper bound on the maximum value of
-- the sensor. This upper bound should be set to a low positive value if
-- no a-priori information is known; NRM will then use a recursive-doubling
-- strategy to maintain its own bound.
{ perfFreq : types.Frequency, perfLimit : Integer }
let ImageType =
-- This type was imported from NRM1: feature not present (yet)
< Sif | Docker >
let Image =
-- This type was imported from NRM1: feature not present (yet)
{ path : Text, imagetype : ImageType, binds : Optional (List Text) }
let PowerPolicy =
-- This type was imported from NRM1: feature not present (yet)
< NoPowerPolicy | DDCM | DVFS | Combined >
let Slice =
-- This type was imported from NRM1: feature not present (yet)
{ cpus : Integer, mems : Integer }
let PowerCfg =
-- This type was imported from NRM1: feature not present (yet)
{ policy : PowerPolicy, profile : Bool, slowdown : Integer }
let Instrumentation =
-- Message rate limitation for libnrm instrumentation.
-- Libnrm instrumentation. The only attribute that configures this feature
-- is a message rate limitation.
{ ratelimit : types.Frequency }
let App -- Application configuration
=
{ slice : Slice
, scheduler : Scheduler
, perfwrapper : Optional Perfwrapper
, powerCfg : PowerCfg
let App =
-- Application configuration. Two features can be enabled or disabled:
-- perfwrapper: an optional linux perf configuration
-- instrumentation: an optional libnrm instrumentation configuration
{ perfwrapper : Optional Perfwrapper
, instrumentation : Optional Instrumentation
}
let Manifest =
-- A manifest has a name, an application configuration.
-- placeholders field from NRM1: hwbind, image
{ name : Text, app : App, hwbind : Bool, image : Optional Image }
-- A manifest has a name, and an application configuration.
{ name : Text, app : App }
in types
⫽ { Scheduler = Scheduler
, Perfwrapper = Perfwrapper
, Image = Image
, ImageType = ImageType
, PowerPolicy = PowerPolicy
, Slice = Slice
, PowerCfg = PowerCfg
⫽ { Perfwrapper = Perfwrapper
, Instrumentation = Instrumentation
, App = App
, Manifest = Manifest
......
......@@ -8,7 +8,10 @@
-- types used by nrmd's configuration.
--
--
let types = ./types.dhall
let types =
-- This import defines a few base types that are common to manifest and
-- configuration formats.
./types.dhall
let Verbosity =
-- Daemon verbosity:
......@@ -19,7 +22,15 @@ let Verbosity =
let SensorBehavior =
-- Sensor Behavior.
< Cumulative | IntervalBased | CumulativeWithCapacity : Double >
-- IntervalBased: a sensor that measures an average value for the time
-- period since its last reading.
-- Cumulative: a sensor that measures a counter. NRM must substract between
-- subsequent counter values to obtain a reading for the corresponding time
-- period.
-- CumulativeWithCapacity: same as `Cumulative`, except the sensor gives
-- bounded values that go back to zero after a given threshold. Typical of
-- RAPL sysfs sensors, for instance .
< IntervalBased | Cumulative | CumulativeWithCapacity : Double >
let Range =
-- An inclusive range of values
......@@ -69,10 +80,6 @@ let SensorKV =
-- Key-value representation for a sensor.
{ sensorID : Text, sensor : Sensor }
let Hwmon =
--- Temperature sensor config (imported from NRM1, placeholder)
{ hwmonEnabled : Bool, hwmonPath : Text }
let RaplCfg =
-- Configuration for auto-discovered RAPL power sensors/actuators
{ raplPath : Text
......@@ -115,22 +122,29 @@ let ControlCfg =
>
let Cfg =
-- The configuration type for nrmd.
-- The configuration type for `nrmd`.
-- verbose : a verbosity level configuration.
-- logfile : the main log file for the daemon.
-- perfPath : the path/binary name of the linux perf executable.
-- perfwrapperPath : the path/binary name of the nrm-perfwrapper executable
-- libnrmPath : the path to the libnrm.so to use. leave at None to disable
-- the feature globally (for all apps).
-- downstreamCfg : Downstream API configuration.
-- upstreamCfg : Upstream API configuration.
-- raplCfg : RAPL configuration. Leave at None to disable the feature
-- globally.
-- controlCfg : resource control configuration
-- passiveSensorFrequency : unified frequency for all NRM's passive sensors.
-- extraStaticPassiveSensors : list of extra static passive sensors.
-- extraStaticActuators : list of extra actuators.
{ verbose : Verbosity
, logfile : Text
, hwloc : Text
, perf : Text
, argo_perf_wrapper : Text
, argo_nodeos_config : Text
, perfPath : Text
, perfwrapperPath : Text
, libnrmPath : Optional Text
, pmpi_lib : Text
, singularity : Bool
, dummy : Bool
, nodeos : Bool
, downstreamCfg : DownstreamCfg
, upstreamCfg : UpstreamCfg
, raplCfg : Optional RaplCfg
, hwmonCfg : Hwmon
, controlCfg : ControlCfg
, passiveSensorFrequency : types.Frequency
, extraStaticPassiveSensors : List SensorKV
......@@ -151,7 +165,6 @@ let output =
, PassiveSensorCfg = Sensor
, ActuatorValue = ActuatorValue
, ActuatorCfg = Actuator
, HwmonCfg = Hwmon
, LearnCfg = LearnCfg
, RaplCfg = RaplCfg
, ControlCfg = ControlCfg
......
......@@ -131,7 +131,7 @@ nrm _callTime (Req clientid msg) =
Nothing -> identity
(Just p@Manifest.Perfwrapper {}) ->
wrapCmd
(Command $ Cfg.argo_perf_wrapper c)
(Command $ Cfg.perfwrapperPath c)
[ "-f",
Arg . show . U.fromHz
. Manifest.toFrequency
......
......@@ -26,9 +26,6 @@ import Data.Map.Merge.Lazy
import NRM.Node.Hwloc
import NRM.Node.Sysfs
import NRM.Node.Sysfs.Internal
import NRM.Slices.Dummy as CD
import NRM.Slices.Nodeos as CN
import NRM.Slices.Singularity as CS
import NRM.Types.Cmd
import NRM.Types.CmdID
import qualified NRM.Types.Configuration as Cfg
......@@ -103,18 +100,6 @@ initialState c time = do
slices = M.fromList [],
pus = M.fromList $ (,PU) <$> selectPUIDs hwl,
cores = M.fromList $ (,Core) <$> selectCoreIDs hwl,
dummyRuntime =
if Cfg.dummy c
then Just CD.emptyRuntime
else Nothing,
singularityRuntime =
if Cfg.singularity c
then Just SingularityRuntime
else Nothing,
nodeosRuntime =
if Cfg.nodeos c
then Just NodeosRuntime
else Nothing,
extraStaticActuators =
Cfg.extraStaticActuators c
& fmap (\Cfg.ActuatorKV {actuatorID, actuator} -> (actuatorID, actuator))
......
......@@ -15,7 +15,6 @@ module NRM.Types.Configuration
DaemonVerbosity (..),
ControlCfg (..),
RaplCfg (..),
HwmonCfg (..),
ExtraPassiveSensor (..),
ActuatorKV (..),
SensorKV (..),
......@@ -71,7 +70,6 @@ makeHaskellTypes $
dSum "Tag" "Tag",
dRec "Range" "Range",
dRec "Frequency" "Frequency",
dRec "HwmonCfg" "HwmonCfg",
dRec "ExtraActuator" "Actuator",
dRec "ActuatorValue" "ActuatorValue",
dSum "Hint" "Hint",
......@@ -158,26 +156,6 @@ deriving via (GenericJSON RaplCfg) instance ToJSON RaplCfg
deriving via (GenericJSON RaplCfg) instance JSONSchema RaplCfg
deriving instance Generic HwmonCfg
deriving instance Eq HwmonCfg
deriving instance Ord HwmonCfg
deriving instance Show HwmonCfg
deriving instance MessagePack HwmonCfg
deriving instance FromDhall HwmonCfg
deriving instance ToDhall HwmonCfg
deriving via (GenericJSON HwmonCfg) instance FromJSON HwmonCfg
deriving via (GenericJSON HwmonCfg) instance ToJSON HwmonCfg
deriving via (GenericJSON HwmonCfg) instance JSONSchema HwmonCfg
deriving instance Generic Tag
deriving instance Eq Tag
......
......@@ -11,14 +11,8 @@
module NRM.Types.Manifest
( Manifest (..),
App (..),
Slice (..),
Scheduler (..),
PowerPolicy (..),
PowerCfg (..),
Instrumentation (..),
ImageType (..),
Perfwrapper (..),
Image (..),
toFrequency,
)
where
......@@ -42,16 +36,8 @@ makeHaskellTypes $
rPath = "(./dhall/types/manifest.dhall)."
dRec :: Text -> Text -> HaskellType Text
dRec s path = SingleConstructor s s (rPath <> path)
dSum :: Text -> Text -> HaskellType Text
dSum s path = MultipleConstructors s (rPath <> path)
in [ dSum "Scheduler" "Scheduler",
dRec "Frequency" "Frequency",
in [ dRec "Frequency" "Frequency",
dRec "Perfwrapper" "Perfwrapper",
dSum "ImageType" "ImageType",
dRec "Image" "Image",
dSum "PowerPolicy" "PowerPolicy",
dRec "Slice" "Slice",
dRec "PowerCfg" "PowerCfg",
dRec "Instrumentation" "Instrumentation",
dRec "App" "App",
dRec "Manifest" "Manifest"
......@@ -79,26 +65,6 @@ instance MessagePack Integer where
fromObject x = (toInteger :: Int -> Integer) <$> fromObject x
deriving instance Generic Scheduler
deriving instance Eq Scheduler
deriving instance Ord Scheduler
deriving instance Show Scheduler
deriving instance MessagePack Scheduler
deriving instance FromDhall Scheduler
deriving instance ToDhall Scheduler
deriving via (GenericJSON Scheduler) instance FromJSON Scheduler
deriving via (GenericJSON Scheduler) instance ToJSON Scheduler
deriving via (GenericJSON Scheduler) instance JSONSchema Scheduler
deriving instance Generic Frequency
deriving instance Eq Frequency
......@@ -139,106 +105,6 @@ deriving via (GenericJSON Perfwrapper) instance ToJSON Perfwrapper
deriving via (GenericJSON Perfwrapper) instance JSONSchema Perfwrapper
deriving instance Generic ImageType
deriving instance Eq ImageType
deriving instance Ord ImageType
deriving instance Show ImageType
deriving instance MessagePack ImageType
deriving instance FromDhall ImageType
deriving instance ToDhall ImageType
deriving via (GenericJSON ImageType) instance FromJSON ImageType
deriving via (GenericJSON ImageType) instance ToJSON ImageType
deriving via (GenericJSON ImageType) instance JSONSchema ImageType
deriving instance Generic Image
deriving instance Eq Image
deriving instance Ord Image
deriving instance Show Image
deriving instance MessagePack Image
deriving instance FromDhall Image
deriving instance ToDhall Image
deriving via (GenericJSON Image) instance FromJSON Image
deriving via (GenericJSON Image) instance ToJSON Image
deriving via (GenericJSON Image) instance JSONSchema Image
deriving instance Generic PowerPolicy
deriving instance Eq PowerPolicy
deriving instance Ord PowerPolicy
deriving instance Show PowerPolicy
deriving instance MessagePack PowerPolicy
deriving instance FromDhall PowerPolicy
deriving instance ToDhall PowerPolicy
deriving via (GenericJSON PowerPolicy) instance FromJSON PowerPolicy
deriving via (GenericJSON PowerPolicy) instance ToJSON PowerPolicy
deriving via (GenericJSON PowerPolicy) instance JSONSchema PowerPolicy
deriving instance Generic Slice
deriving instance Eq Slice
deriving instance Ord Slice
deriving instance Show Slice
deriving instance MessagePack Slice
deriving instance FromDhall Slice
deriving instance ToDhall Slice
deriving via (GenericJSON Slice) instance FromJSON Slice
deriving via (GenericJSON Slice) instance ToJSON Slice
deriving via (GenericJSON Slice) instance JSONSchema Slice
deriving instance Generic PowerCfg
deriving instance Eq PowerCfg
deriving instance Ord PowerCfg
deriving instance Show PowerCfg
deriving instance MessagePack PowerCfg
deriving instance FromDhall PowerCfg
deriving instance ToDhall PowerCfg
deriving via (GenericJSON PowerCfg) instance FromJSON PowerCfg
deriving via (GenericJSON PowerCfg) instance ToJSON PowerCfg
deriving via (GenericJSON PowerCfg) instance JSONSchema PowerCfg
deriving instance Generic Instrumentation
deriving instance Eq Instrumentation
......
......@@ -37,9 +37,6 @@ import Data.Map as M
import Data.MessagePack
import Data.Scientific
import LensMap.Core
import NRM.Slices.Dummy
import NRM.Slices.Nodeos
import NRM.Slices.Singularity
import qualified NRM.Types.Actuator as A
import NRM.Types.Cmd
import NRM.Types.CmdID as CmdID
......@@ -63,9 +60,6 @@ data NRMState
cores :: M.Map CoreID Core,
packages :: M.Map PackageID Package,
slices :: Map SliceID Slice,
dummyRuntime :: Maybe DummyRuntime,
singularityRuntime :: Maybe SingularityRuntime,
nodeosRuntime :: Maybe NodeosRuntime,
controller :: Maybe Controller,
extraStaticActuators :: Map Text Cfg.ExtraActuator,
extraStaticPassiveSensors :: Map Text ExtraPassiveSensor
......
{
"image": null,
"hwbind": false,
"app": {
"scheduler": "FIFO",
"instrumentation": null,
"perfwrapper": null,
"powerCfg": {
"slowdown": 1,
"profile": false,
"policy": "NoPowerPolicy"
},
"slice": {
"cpus": 1,
"mems": 1
}
"perfwrapper": null
},
"name": "default"
}
\ No newline at end of file
{
"extraStaticPassiveSensors": [],
"pmpi_lib": "pmpi_lib",
"perfPath": "perf",
"verbose": "Error",
"logfile": "/tmp/nrm.log",
"singularity": false,
"argo_nodeos_config": "argo_nodeos_config",
"controlCfg": "ControlOff",
"upstreamCfg": {
"upstreamBindAddress": "*",
......@@ -12,13 +10,10 @@
"pubPort": 2345
},
"libnrmPath": null,
"perf": "perf",
"argo_perf_wrapper": "nrm-perfwrapper",
"downstreamCfg": {
"downstreamBindAddress": "ipc:///tmp/nrm-downstream-event"
},
"nodeos": false,
"hwloc": "hwloc",
"perfwrapperPath": "nrm-perfwrapper",
"extraStaticActuators": [],
"raplCfg": {
"referencePower": {
......@@ -34,11 +29,6 @@
],
"raplPath": "/sys/devices/virtual/powercap/intel-rapl"
},
"dummy": true,
"hwmonCfg": {
"hwmonPath": "/sys/class/hwmon",
"hwmonEnabled": true
},
"passiveSensorFrequency": {
"hertz": 1
}
......
This diff is collapsed.
......@@ -58,90 +58,13 @@
"manifest": {
"required": [
"app",
"hwbind",
"name"
],
"type": "object",
"properties": {
"image": {
"required": [