📄 xc.c
字号:
return zero;}static PyObject *pyxc_dom_set_cpuid(XcObject *self, PyObject *args){ domid_t domid; PyObject *sub_input, *config; unsigned int input[2]; char *regs[4], *regs_transform[4]; if ( !PyArg_ParseTuple(args, "IIOO", &domid, &input[0], &sub_input, &config) ) return NULL; pyxc_dom_extract_cpuid(config, regs); input[1] = XEN_CPUID_INPUT_UNUSED; if ( PyLong_Check(sub_input) ) input[1] = PyLong_AsUnsignedLong(sub_input); if ( xc_cpuid_set(self->xc_handle, domid, input, (const char **)regs, regs_transform) ) return pyxc_error_to_exception(); return pyxc_create_cpuid_dict(regs_transform);}static PyObject *pyxc_dom_set_machine_address_size(XcObject *self, PyObject *args, PyObject *kwds){ uint32_t dom, width; if (!PyArg_ParseTuple(args, "ii", &dom, &width)) return NULL; if (xc_domain_set_machine_address_size(self->xc_handle, dom, width) != 0) return pyxc_error_to_exception(); Py_INCREF(zero); return zero;}#endif /* __i386__ || __x86_64__ */static PyObject *pyxc_hvm_build(XcObject *self, PyObject *args, PyObject *kwds){ uint32_t dom;#if !defined(__ia64__) struct hvm_info_table *va_hvm; uint8_t *va_map, sum; int i;#endif char *image; int memsize, vcpus = 1, acpi = 0, apic = 1; static char *kwd_list[] = { "domid", "memsize", "image", "vcpus", "acpi", "apic", NULL }; if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iis|iii", kwd_list, &dom, &memsize, &image, &vcpus, &acpi, &apic) ) return NULL; if ( xc_hvm_build(self->xc_handle, dom, memsize, image) != 0 ) return pyxc_error_to_exception();#if !defined(__ia64__) /* Set up the HVM info table. */ va_map = xc_map_foreign_range(self->xc_handle, dom, XC_PAGE_SIZE, PROT_READ | PROT_WRITE, HVM_INFO_PFN); if ( va_map == NULL ) return PyErr_SetFromErrno(xc_error_obj); va_hvm = (struct hvm_info_table *)(va_map + HVM_INFO_OFFSET); memset(va_hvm, 0, sizeof(*va_hvm)); strncpy(va_hvm->signature, "HVM INFO", 8); va_hvm->length = sizeof(struct hvm_info_table); va_hvm->acpi_enabled = acpi; va_hvm->apic_mode = apic; va_hvm->nr_vcpus = vcpus; for ( i = 0, sum = 0; i < va_hvm->length; i++ ) sum += ((uint8_t *)va_hvm)[i]; va_hvm->checksum = -sum; munmap(va_map, XC_PAGE_SIZE);#endif return Py_BuildValue("{}");}static PyObject *pyxc_evtchn_alloc_unbound(XcObject *self, PyObject *args, PyObject *kwds){ uint32_t dom, remote_dom; int port; static char *kwd_list[] = { "domid", "remote_dom", NULL }; if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list, &dom, &remote_dom) ) return NULL; if ( (port = xc_evtchn_alloc_unbound(self->xc_handle, dom, remote_dom)) < 0 ) return pyxc_error_to_exception(); return PyInt_FromLong(port);}static PyObject *pyxc_evtchn_reset(XcObject *self, PyObject *args, PyObject *kwds){ uint32_t dom; static char *kwd_list[] = { "dom", NULL }; if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, &dom) ) return NULL; if ( xc_evtchn_reset(self->xc_handle, dom) < 0 ) return pyxc_error_to_exception(); Py_INCREF(zero); return zero;}static PyObject *pyxc_physdev_map_pirq(PyObject *self, PyObject *args, PyObject *kwds){ XcObject *xc = (XcObject *)self; uint32_t dom; int index, pirq, ret; static char *kwd_list[] = {"domid", "index", "pirq", NULL}; if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iii", kwd_list, &dom, &index, &pirq) ) return NULL; ret = xc_physdev_map_pirq(xc->xc_handle, dom, index, &pirq); if ( ret != 0 ) return pyxc_error_to_exception(); return PyLong_FromUnsignedLong(pirq);}static PyObject *pyxc_physdev_pci_access_modify(XcObject *self, PyObject *args, PyObject *kwds){ uint32_t dom; int bus, dev, func, enable, ret; static char *kwd_list[] = { "domid", "bus", "dev", "func", "enable", NULL }; if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiii", kwd_list, &dom, &bus, &dev, &func, &enable) ) return NULL; ret = xc_physdev_pci_access_modify( self->xc_handle, dom, bus, dev, func, enable); if ( ret != 0 ) return pyxc_error_to_exception(); Py_INCREF(zero); return zero;}static PyObject *pyxc_readconsolering(XcObject *self, PyObject *args, PyObject *kwds){ unsigned int clear = 0, index = 0, incremental = 0; char _str[32768], *str = _str; unsigned int count = 32768; int ret; static char *kwd_list[] = { "clear", "index", "incremental", NULL }; if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iii", kwd_list, &clear, &index, &incremental) ) return NULL; ret = xc_readconsolering(self->xc_handle, &str, &count, clear, incremental, &index); if ( ret < 0 ) return pyxc_error_to_exception(); return PyString_FromStringAndSize(str, count);}static unsigned long pages_to_kib(unsigned long pages){ return pages * (XC_PAGE_SIZE / 1024);}static PyObject *pyxc_pages_to_kib(XcObject *self, PyObject *args){ unsigned long pages; if (!PyArg_ParseTuple(args, "l", &pages)) return NULL; return PyLong_FromUnsignedLong(pages_to_kib(pages));}static PyObject *pyxc_physinfo(XcObject *self){#define MAX_CPU_ID 255 xc_physinfo_t info; char cpu_cap[128], virt_caps[128], *p; int i, j, max_cpu_id; uint64_t free_heap; PyObject *ret_obj, *node_to_cpu_obj, *node_to_memory_obj; xc_cpu_to_node_t map[MAX_CPU_ID + 1]; const char *virtcap_names[] = { "hvm", "hvm_directio" }; set_xen_guest_handle(info.cpu_to_node, map); info.max_cpu_id = MAX_CPU_ID; if ( xc_physinfo(self->xc_handle, &info) != 0 ) return pyxc_error_to_exception(); p = cpu_cap; *p = '\0'; for ( i = 0; i < sizeof(info.hw_cap)/4; i++ ) p += sprintf(p, "%08x:", info.hw_cap[i]); *(p-1) = 0; p = virt_caps; *p = '\0'; for ( i = 0; i < 2; i++ ) if ( (info.capabilities >> i) & 1 ) p += sprintf(p, "%s ", virtcap_names[i]); if ( p != virt_caps ) *(p-1) = '\0'; ret_obj = Py_BuildValue("{s:i,s:i,s:i,s:i,s:i,s:l,s:l,s:l,s:i,s:s:s:s}", "nr_nodes", info.nr_nodes, "max_cpu_id", info.max_cpu_id, "threads_per_core", info.threads_per_core, "cores_per_socket", info.cores_per_socket, "nr_cpus", info.nr_cpus, "total_memory", pages_to_kib(info.total_pages), "free_memory", pages_to_kib(info.free_pages), "scrub_memory", pages_to_kib(info.scrub_pages), "cpu_khz", info.cpu_khz, "hw_caps", cpu_cap, "virt_caps", virt_caps); max_cpu_id = info.max_cpu_id; if ( max_cpu_id > MAX_CPU_ID ) max_cpu_id = MAX_CPU_ID; /* Construct node-to-cpu lists. */ node_to_cpu_obj = PyList_New(0); /* Make a list for each node. */ for ( i = 0; i < info.nr_nodes; i++ ) { PyObject *cpus = PyList_New(0); for ( j = 0; j <= max_cpu_id; j++ ) if ( i == map[j]) PyList_Append(cpus, PyInt_FromLong(j)); PyList_Append(node_to_cpu_obj, cpus); } node_to_memory_obj = PyList_New(0); for ( i = 0; i < info.nr_nodes; i++ ) { xc_availheap(self->xc_handle, 0, 0, i, &free_heap); PyList_Append(node_to_memory_obj, PyInt_FromLong(free_heap / 1024)); } PyDict_SetItemString(ret_obj, "node_to_cpu", node_to_cpu_obj); PyDict_SetItemString(ret_obj, "node_to_memory", node_to_memory_obj); return ret_obj;#undef MAX_CPU_ID}static PyObject *pyxc_xeninfo(XcObject *self){ xen_extraversion_t xen_extra; xen_compile_info_t xen_cc; xen_changeset_info_t xen_chgset; xen_capabilities_info_t xen_caps; xen_platform_parameters_t p_parms; long xen_version; long xen_pagesize; char str[128]; xen_version = xc_version(self->xc_handle, XENVER_version, NULL); if ( xc_version(self->xc_handle, XENVER_extraversion, &xen_extra) != 0 ) return pyxc_error_to_exception(); if ( xc_version(self->xc_handle, XENVER_compile_info, &xen_cc) != 0 ) return pyxc_error_to_exception(); if ( xc_version(self->xc_handle, XENVER_changeset, &xen_chgset) != 0 ) return pyxc_error_to_exception(); if ( xc_version(self->xc_handle, XENVER_capabilities, &xen_caps) != 0 ) return pyxc_error_to_exception(); if ( xc_version(self->xc_handle, XENVER_platform_parameters, &p_parms) != 0 ) return pyxc_error_to_exception(); snprintf(str, sizeof(str), "virt_start=0x%lx", p_parms.virt_start); xen_pagesize = xc_version(self->xc_handle, XENVER_pagesize, NULL); if (xen_pagesize < 0 ) return pyxc_error_to_exception(); return Py_BuildValue("{s:i,s:i,s:s,s:s,s:i,s:s,s:s,s:s,s:s,s:s,s:s}", "xen_major", xen_version >> 16, "xen_minor", (xen_version & 0xffff), "xen_extra", xen_extra, "xen_caps", xen_caps, "xen_pagesize", xen_pagesize, "platform_params", str, "xen_changeset", xen_chgset, "cc_compiler", xen_cc.compiler, "cc_compile_by", xen_cc.compile_by, "cc_compile_domain", xen_cc.compile_domain, "cc_compile_date", xen_cc.compile_date);}static PyObject *pyxc_sedf_domain_set(XcObject *self, PyObject *args, PyObject *kwds){ uint32_t domid; uint64_t period, slice, latency; uint16_t extratime, weight; static char *kwd_list[] = { "domid", "period", "slice", "latency", "extratime", "weight",NULL }; if( !PyArg_ParseTupleAndKeywords(args, kwds, "iLLLhh", kwd_list, &domid, &period, &slice, &latency, &extratime, &weight) ) return NULL; if ( xc_sedf_domain_set(self->xc_handle, domid, period, slice, latency, extratime,weight) != 0 ) return pyxc_error_to_exception(); Py_INCREF(zero); return zero;}static PyObject *pyxc_sedf_domain_get(XcObject *self, PyObject *args){ uint32_t domid; uint64_t period, slice,latency; uint16_t weight, extratime; if(!PyArg_ParseTuple(args, "i", &domid)) return NULL; if (xc_sedf_domain_get(self->xc_handle, domid, &period, &slice,&latency,&extratime,&weight)) return pyxc_error_to_exception(); return Py_BuildValue("{s:i,s:L,s:L,s:L,s:i,s:i}", "domid", domid, "period", period, "slice", slice, "latency", latency, "extratime", extratime, "weight", weight);}static PyObject *pyxc_shadow_control(PyObject *self, PyObject *args, PyObject *kwds){ XcObject *xc = (XcObject *)self; uint32_t dom; int op=0; static char *kwd_list[] = { "dom", "op", NULL }; if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list, &dom, &op) ) return NULL; if ( xc_shadow_control(xc->xc_handle, dom, op, NULL, 0, NULL, 0, NULL) < 0 ) return pyxc_error_to_exception(); Py_INCREF(zero); return zero;}static PyObject *pyxc_shadow_mem_control(PyObject *self, PyObject *args,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -