/* * xen_exec.c - hunt xen plugins * * Copyright (C) 2007 Intel Corporation * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * Authors: * Haicheng Li * */ #include #include #include #define _GNU_SOURCE #include #include #define CPU_NUM 128 xc_interface *xen_fd = 0; int cpus[CPU_NUM] = { 0 }; int cpu_num = 0; int offline = 1; static int xen_cpu_online(void) { int rc = 0, err = 0, i; for (i = 0; i < cpu_num; i++) { rc = xc_cpu_online(xen_fd, cpus[i]); if (rc < 0) { fprintf(stderr, "failed to online cpu%d : %s\n", cpus[i], strerror(errno)); err++; } else fprintf(stdout, "cpu%d is online\n", cpus[i]); } } static int xen_cpu_offline(void) { int rc = 0, err = 0, i; for (i = 0; i < cpu_num; i++) { rc = xc_cpu_offline(xen_fd, cpus[i]); if (rc < 0) { fprintf(stderr, "failed to offline cpu%d : %s\n", cpus[i], strerror(errno)); err++; } else fprintf(stdout, "cpu%d is offline\n", cpus[i]); } } void usage(void) { printf("./cpu_hp [-a|-d|-h] cpuid \n"); return; } int main(int argc, char **argv) { int rc = 0, i; cpu_num = argc - 1; if (cpu_num <= 0) { fprintf(stderr, "no cpu specified\n"); rc = 1; goto error; } for (i = 0; i < cpu_num; i++) { cpus[i] = atoi(argv[i+1]); } xen_fd = xc_interface_open(0,0,0); if (!xen_fd) { rc = 1; fprintf(stderr, "failed to open xc interface: %s\n", strerror(errno)); } if (offline) xen_cpu_offline(); else xen_cpu_online(); error: return rc; }