Xen源码阅读笔记

From Yefu's notes
Jump to: navigation, search

通过搜索引擎来到此页的同学请注意:本文是我的乱记本,不是给外人读的,所以写的没有什么可读性,请见谅。

文件

有两个sched.h,猜测include\public\sched.h是给外面调用的,include\xen\sched.h是在Xen内核里面用的。 interface的声明在sched-if.h里, 并且This should * only be included by files that implement conforming schedulers.

新的scheduler要放在 schedule.c

static const struct scheduler *__initdata schedulers[] = {
    &sched_sedf_def,
    &sched_credit_def,
    NULL
};

domain

看struct domain里面跟Scheduler 相关的可能有:

struct domain
{
    /* Scheduling. */
    void            *sched_priv;    /* scheduler-specific data */

    struct domain   *next_in_list;
    struct domain   *next_in_hashbucket;

    struct list_head rangesets;
    spinlock_t       rangesets_lock;

 //貌似还有一个vcpu的list
   struct vcpu    **vcpu;
//当然还有其他的
}

这至少说明了domain 是有一个list的

put_domain和get_domain是做什么用的?往哪put/get?,其参数是struct domain*

取得当前的domain:

static inline struct domain *get_current_domain(void);

vcpu

这东西对统计utilization肯定有用

struct vcpu_runstate_info {
    /* VCPU's current state (RUNSTATE_*). */
    int      state;
    /* When was current state entered (system time, ns)? */
    uint64_t state_entry_time;
    /*
     * Time spent in each RUNSTATE_* (ns). The sum of these times is
     * guaranteed not to drift from system time.
     */
    uint64_t time[4];
};
//可能的state有:
/* VCPU is currently running on a physical CPU. */
#define RUNSTATE_running  0

/* VCPU is runnable, but not currently scheduled on any physical CPU. */
#define RUNSTATE_runnable 1

/* VCPU is blocked (a.k.a. idle). It is therefore not runnable. */
#define RUNSTATE_blocked  2

/*
 * VCPU is not runnable, but it is not blocked.
 * This is a 'catch all' state for things like hotplug and pauses by the
 * system administrator (or for critical sections in the hypervisor).
 * RUNSTATE_blocked dominates this state (it is the preferred state).
 */
#define RUNSTATE_offline  3

domain control

在domctrl.h里:

#define XEN_SCHEDULER_SEDF     4
#define XEN_SCHEDULER_CREDIT   5

最终这东西赋值给scheduler.sched_id。可能还不是完全无用的。

命令传递

xenpm命令的参数传递的定义在 struct xen_sysctl_pm_op, sysctrl.h里

debug mode

set "debug = y" in Config.mk in the Xen source tree

Debug的方法在这里,基本要这样:

xm debug-key h

xm dmesg

其实还可以-c

Credit Scheduler

结构图