Skip to content
aglitke edited this page Dec 29, 2010 · 25 revisions

MOM is designed to enable dynamic tuning of a KVM host in response to statistics that are continuously collected from the host and its running guests.
This tuning policy is described using a LISP-like mini-language as described here.

Comments

Comments are expressed with the ‘#’ symbol. When ‘#’ is encountered, it and all remaining characters on the line are ignored.

Example:

Code Result

# This is a full line comment
(+ 1 1) # This is a partial-line comment

 
2

Strings

Strings are created by placing text between double-quotes. Variables can be assigned string values. Sting concatenation and repetition can be performed by using the ‘+’ and ‘*’ operators.

Example:

Code Result

"foo" "bar"
# Operators on strings have the same effect as for Python
(+ "Hello " "World!")
(+ (* 3 "Hey ") "!")
# Multi-line string
"multi-
line"

foo
bar
Hello World!
Hey Hey Hey !

multi-
line

Numbers

Numbers can be expressed as a floating point, integer, integer in scientific notation, hexidecimal, and octal. However, numerical results are always base 10 integers or floats. The basic arithmetic operators +, -, *, /, <<. and >> are supported and have their usual meanings.

Example:

Code Result

10
00                  # Octal
.3                  # The leading 0 on a float is not required
(* 0 1)
(+ 1 2)
(/ 11 2)            # Integer division
(/ 11 2.0)          # Floating point division
(* 3 6)
(- 1 9)             # Negative result
(* (- 8 6) 9)
(>> (<< 1 4) 2)
(+ 0xFF 0x1)        # Hex numbers
(* 011 02)
(+ 0xa 10)          # Numeric type mixing
(+ 10.0e3 100e-2)   # Scientific notation for integers and floats

10
0
0.3
0
3
5
5.5
18
-8
18
4
256
18
20
10001.0

Logic and Comparison

The policy language supports 3 logic operators: and, or, not. These operators use short-circuit logic behavior equivalent to the Python language. See the example below for more details. In addition to the logic operators, comparisons are supported using: <, >, <=, >=, ==, and !=.

Example:

Code Result

(and 1 "")          # The values 0 and "" evaluate to False
                    # Everything else evaluates to True
(and 0 1)           # 'and' returns the first False value
(and 1 2)           # if all values are True, the last value is returned
(or "" 17)          # 'or' returns the first True value encountered
(or "" "")          # if all values are False, 'or' returns the last one
(not "")
(not -0)

(< 5 4)
(> 1 0)
(<= 10 10)
(>= 2 (/ 10 2))
(== (+ 1 2) (/ 9 3))
(!= "foo" "foo")
(== 0x0 0)

""

0
2
17
""
True
True
 
False
True
True
False
True
False
True

Compound Statements

Remember to state that the result of a compound statement is the last value in the block.

Variables and Scope

Macros

The let Statement

The if Statement

Entities

The Input Entities: Host and Guests

Input Entity Methods

Prop, Stat, StatAvg, SetVar, GetVar

Controller Entities

Control()

The with Guests Construct

External Functions

  • (abs x): Return the absolute value of ‘x’
Clone this wiki locally