From patchwork Sat Jan 22 01:30:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 497491 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p0M1VEZ5022962 for ; Sat, 22 Jan 2011 01:31:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753163Ab1AVBbD (ORCPT ); Fri, 21 Jan 2011 20:31:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:62953 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752674Ab1AVBbB (ORCPT ); Fri, 21 Jan 2011 20:31:01 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p0M1V0Ca015707 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 21 Jan 2011 20:31:00 -0500 Received: from freedom.redhat.com (vpn-11-112.rdu.redhat.com [10.11.11.112]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p0M1Up5O007822; Fri, 21 Jan 2011 20:30:58 -0500 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Lucas Meneghel Rodrigues Subject: [PATCH 4/6] KVM config: Move HugePageConfig() to test_setup Date: Fri, 21 Jan 2011 23:30:48 -0200 Message-Id: <1295659850-29609-4-git-send-email-lmr@redhat.com> In-Reply-To: <1295659850-29609-1-git-send-email-lmr@redhat.com> References: <1295659850-29609-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sat, 22 Jan 2011 01:31:16 +0000 (UTC) diff --git a/client/tests/kvm/kvm_preprocessing.py b/client/tests/kvm/kvm_preprocessing.py index 12adb6a..081a13f 100644 --- a/client/tests/kvm/kvm_preprocessing.py +++ b/client/tests/kvm/kvm_preprocessing.py @@ -255,7 +255,7 @@ def preprocess(test, params, env): test.write_test_keyval({"kvm_userspace_version": kvm_userspace_version}) if params.get("setup_hugepages") == "yes": - h = kvm_utils.HugePageConfig(params) + h = test_setup.HugePageConfig(params) h.setup() if params.get("type") == "unattended_install": diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index 632badb..78c9f25 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -1265,107 +1265,6 @@ class KvmLoggingConfig(logging_config.LoggingConfig): verbose=verbose) -class HugePageConfig: - def __init__(self, params): - """ - Gets environment variable values and calculates the target number - of huge memory pages. - - @param params: Dict like object containing parameters for the test. - """ - self.vms = len(params.objects("vms")) - self.mem = int(params.get("mem")) - self.max_vms = int(params.get("max_vms", 0)) - self.hugepage_path = '/mnt/kvm_hugepage' - self.hugepage_size = self.get_hugepage_size() - self.target_hugepages = self.get_target_hugepages() - self.kernel_hp_file = '/proc/sys/vm/nr_hugepages' - - - def get_hugepage_size(self): - """ - Get the current system setting for huge memory page size. - """ - meminfo = open('/proc/meminfo', 'r').readlines() - huge_line_list = [h for h in meminfo if h.startswith("Hugepagesize")] - try: - return int(huge_line_list[0].split()[1]) - except ValueError, e: - raise ValueError("Could not get huge page size setting from " - "/proc/meminfo: %s" % e) - - - def get_target_hugepages(self): - """ - Calculate the target number of hugepages for testing purposes. - """ - if self.vms < self.max_vms: - self.vms = self.max_vms - # memory of all VMs plus qemu overhead of 64MB per guest - vmsm = (self.vms * self.mem) + (self.vms * 64) - return int(vmsm * 1024 / self.hugepage_size) - - - @error.context_aware - def set_hugepages(self): - """ - Sets the hugepage limit to the target hugepage value calculated. - """ - error.context("setting hugepages limit to %s" % self.target_hugepages) - hugepage_cfg = open(self.kernel_hp_file, "r+") - hp = hugepage_cfg.readline() - while int(hp) < self.target_hugepages: - loop_hp = hp - hugepage_cfg.write(str(self.target_hugepages)) - hugepage_cfg.flush() - hugepage_cfg.seek(0) - hp = int(hugepage_cfg.readline()) - if loop_hp == hp: - raise ValueError("Cannot set the kernel hugepage setting " - "to the target value of %d hugepages." % - self.target_hugepages) - hugepage_cfg.close() - logging.debug("Successfuly set %s large memory pages on host ", - self.target_hugepages) - - - @error.context_aware - def mount_hugepage_fs(self): - """ - Verify if there's a hugetlbfs mount set. If there's none, will set up - a hugetlbfs mount using the class attribute that defines the mount - point. - """ - error.context("mounting hugepages path") - if not os.path.ismount(self.hugepage_path): - if not os.path.isdir(self.hugepage_path): - os.makedirs(self.hugepage_path) - cmd = "mount -t hugetlbfs none %s" % self.hugepage_path - utils.system(cmd) - - - def setup(self): - logging.debug("Number of VMs this test will use: %d", self.vms) - logging.debug("Amount of memory used by each vm: %s", self.mem) - logging.debug("System setting for large memory page size: %s", - self.hugepage_size) - logging.debug("Number of large memory pages needed for this test: %s", - self.target_hugepages) - self.set_hugepages() - self.mount_hugepage_fs() - - - @error.context_aware - def cleanup(self): - error.context("trying to dealocate hugepage memory") - try: - utils.system("umount %s" % self.hugepage_path) - except error.CmdError: - return - utils.system("echo 0 > %s" % self.kernel_hp_file) - logging.debug("Hugepage memory successfuly dealocated") - - class PciAssignable(object): """ Request PCI assignable devices on host. It will check whether to request diff --git a/client/tests/kvm/test_setup.py b/client/tests/kvm/test_setup.py index 7b7ef14..b17c473 100644 --- a/client/tests/kvm/test_setup.py +++ b/client/tests/kvm/test_setup.py @@ -492,3 +492,104 @@ class UnattendedInstallConfig(object): else: raise ValueError("Unexpected installation method %s" % self.medium) + + +class HugePageConfig(object): + def __init__(self, params): + """ + Gets environment variable values and calculates the target number + of huge memory pages. + + @param params: Dict like object containing parameters for the test. + """ + self.vms = len(params.objects("vms")) + self.mem = int(params.get("mem")) + self.max_vms = int(params.get("max_vms", 0)) + self.hugepage_path = '/mnt/kvm_hugepage' + self.hugepage_size = self.get_hugepage_size() + self.target_hugepages = self.get_target_hugepages() + self.kernel_hp_file = '/proc/sys/vm/nr_hugepages' + + + def get_hugepage_size(self): + """ + Get the current system setting for huge memory page size. + """ + meminfo = open('/proc/meminfo', 'r').readlines() + huge_line_list = [h for h in meminfo if h.startswith("Hugepagesize")] + try: + return int(huge_line_list[0].split()[1]) + except ValueError, e: + raise ValueError("Could not get huge page size setting from " + "/proc/meminfo: %s" % e) + + + def get_target_hugepages(self): + """ + Calculate the target number of hugepages for testing purposes. + """ + if self.vms < self.max_vms: + self.vms = self.max_vms + # memory of all VMs plus qemu overhead of 64MB per guest + vmsm = (self.vms * self.mem) + (self.vms * 64) + return int(vmsm * 1024 / self.hugepage_size) + + + @error.context_aware + def set_hugepages(self): + """ + Sets the hugepage limit to the target hugepage value calculated. + """ + error.context("setting hugepages limit to %s" % self.target_hugepages) + hugepage_cfg = open(self.kernel_hp_file, "r+") + hp = hugepage_cfg.readline() + while int(hp) < self.target_hugepages: + loop_hp = hp + hugepage_cfg.write(str(self.target_hugepages)) + hugepage_cfg.flush() + hugepage_cfg.seek(0) + hp = int(hugepage_cfg.readline()) + if loop_hp == hp: + raise ValueError("Cannot set the kernel hugepage setting " + "to the target value of %d hugepages." % + self.target_hugepages) + hugepage_cfg.close() + logging.debug("Successfuly set %s large memory pages on host ", + self.target_hugepages) + + + @error.context_aware + def mount_hugepage_fs(self): + """ + Verify if there's a hugetlbfs mount set. If there's none, will set up + a hugetlbfs mount using the class attribute that defines the mount + point. + """ + error.context("mounting hugepages path") + if not os.path.ismount(self.hugepage_path): + if not os.path.isdir(self.hugepage_path): + os.makedirs(self.hugepage_path) + cmd = "mount -t hugetlbfs none %s" % self.hugepage_path + utils.system(cmd) + + + def setup(self): + logging.debug("Number of VMs this test will use: %d", self.vms) + logging.debug("Amount of memory used by each vm: %s", self.mem) + logging.debug("System setting for large memory page size: %s", + self.hugepage_size) + logging.debug("Number of large memory pages needed for this test: %s", + self.target_hugepages) + self.set_hugepages() + self.mount_hugepage_fs() + + + @error.context_aware + def cleanup(self): + error.context("trying to dealocate hugepage memory") + try: + utils.system("umount %s" % self.hugepage_path) + except error.CmdError: + return + utils.system("echo 0 > %s" % self.kernel_hp_file) + logging.debug("Hugepage memory successfuly dealocated")