Kernel Parameters

 

 


Goal

 

  1. Kernel behavior should be dynamically changed at runtime. For example, how much physical memory a single application can lock. The configurable variables should be preserved across boot so it must be saved in a file.

 

  1. If the file is in binary format, then it will be very difficult for the user/developer to modify the kernel, without using a special editor. For this reason the file should be in text format.

 

  1. This dynamic behavior is preferred even before the kernel boots and initializes itself. For example, the port on which GDB listens for debugging should be dynamic.

 

 

Implementation

 

Implementing kernel variables as hierarchy path might look very good. However in most of the kernels, the configurable variables are very less(less than 1000). So a static array is more than enough for a micro kernel with very less dynamic variables.

 

Saving and loading kernel parameters from a file will be suspended until File System code is ready.

 

Using Multiboot kernel parameter option, boot time arguments can be passed to kernel. So the current kernel parameter design will use grub/menu.lst file as storage for kernel parameters.

 

Kernel parameter should be architecture independent code but it can contain architecture dependent kernel variables.


Code Flow

 

A static array “kernel_parameters” in param.c is used to track all the kernel parameters.

 

While populating the kernel parameters with new value, the kernel parameter module will call back the subsystem’s routines to validate the given value. After validating the values, the kernel won’t assign the value directly; instead it will call the subsystems assign routine. After successful assignment, it will call back the subsystem to notify, kernel parameter is updated successfully.

 

  1. Kernel Parameter calls subsystem’s ValidateParameter() function to validate the given value for a parameter
  2. ValidateParameter() function returns success or failure
  3. Kernel Parameter calls subsystem’s AssignParameter() function to assign value.
  4. AssignValue() returns success or failure
  5. Kernel Parameter notifies the subsystem’s parameter change through CompleteAssignment() function.

 

 


Data structure

 

typedef struct kernel_parameter KERNEL_PARAMETER, KERNEL_PARAMETER_PTR;

 

struct kernel_parameter

{

       char parameter_name[30];

       void * value_pointer;

 

       int (*ValidateParameter(KERNEL_PARAMETER_PTR kp, void * new_value,

UINT32 arg1, UINT32 arg2, UINT32 arg3) )

       UINT32 ValidateParameterArg[3];

 

       int (*AssignParameterStart(KERNEL_PARAMETER_PTR kp, void * new_value));

int (*AssignParameterComplete(KERNEL_PARAMETER_PTR kp ));

};

 

Parameter_name uniquely identifies a kernel parameter.

value_pointer points to the kernel parameter variable / array.

 

ValidateParameter will be called when a new value is identified for the kernel parameter. Each kernel parameter can provide its own validator or it can use generic validators.

 

ValidateParameterArg will be passed to the ValidateParameter function when it gets called.

 

AssignParameterStart will be get called with new value if ValidateParamter is successful.

 

If AssignParameterStart is successful then AssignParameterComplete will be called to complete the operation.

 

KERNEL_PARAMETER kernel_parameters[]=

{

       All the kernel parameter declaration goes here.

};