From patchwork Tue Feb 11 06:41:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 319163 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B1B412C00B8 for ; Tue, 11 Feb 2014 18:14:20 +1100 (EST) Received: from localhost ([::1]:59837 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WD743-0003wo-Ez for incoming@patchwork.ozlabs.org; Tue, 11 Feb 2014 01:43:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56563) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WD726-0001hT-4e for qemu-devel@nongnu.org; Tue, 11 Feb 2014 01:41:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WD721-0003Gt-9U for qemu-devel@nongnu.org; Tue, 11 Feb 2014 01:41:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:29932) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WD721-0003Gp-0u for qemu-devel@nongnu.org; Tue, 11 Feb 2014 01:41:21 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1B6fIYO002394 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 11 Feb 2014 01:41:18 -0500 Received: from T430.nay.redhat.com ([10.66.6.88]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s1B6esfI017497; Tue, 11 Feb 2014 01:41:15 -0500 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 11 Feb 2014 14:41:02 +0800 Message-Id: <1392100862-25943-6-git-send-email-famz@redhat.com> In-Reply-To: <1392100862-25943-1-git-send-email-famz@redhat.com> References: <1392100862-25943-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , =?UTF-8?q?Beno=C3=AEt=20Canet?= , Stefan Hajnoczi , pbonzini@redhat.com Subject: [Qemu-devel] [PATCH v3 5/5] qemu-iotests: Add 080 for IO throttling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This case utilizes qemu-io command "aio_{read,write} -q" to verify the effectiveness of IO throttling options. It's implemented by driving the vm timer from qtest protocol, so the throttling timers are signaled with determined time duration. Then we verify the completed IO requests are within 110% of bps and iops limits. Signed-off-by: Fam Zheng Reviewed-by: Benoit Canet --- tests/qemu-iotests/080 | 175 +++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/080.out | 5 ++ tests/qemu-iotests/group | 1 + 3 files changed, 181 insertions(+) create mode 100755 tests/qemu-iotests/080 create mode 100644 tests/qemu-iotests/080.out diff --git a/tests/qemu-iotests/080 b/tests/qemu-iotests/080 new file mode 100755 index 0000000..9e2c762 --- /dev/null +++ b/tests/qemu-iotests/080 @@ -0,0 +1,175 @@ +#!/usr/bin/env python +# +# Tests for IO throttling +# +# Copyright (C) 2014 Red Hat, Inc. +# +# 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, see . +# + +import time +import os +import iotests +from iotests import qemu_img + +test_img = os.path.join(iotests.test_dir, 'test.img') + +class ThrottleTestCase(iotests.QMPTestCase): + + def blockstats(self, device): + result = self.vm.qmp("query-blockstats") + for r in result['return']: + if r['device'] == device: + stat = r['stats'] + return stat['rd_bytes'], stat['rd_operations'], stat['wr_bytes'], stat['wr_operations'] + raise Exception("Device not found for blockstats: %s" % device) + + def setUp(self): + qemu_img('create', '-f', iotests.imgfmt, test_img, "1G") + self.vm = iotests.VM().add_drive(test_img) + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + os.remove(test_img) + + def do_test_throttle(self, seconds=20, **limits): + def check_limit(limit, num): + # IO throttling algorithm is discrete, allow 10% error so the test + # is more deterministic + v = limit * seconds + return limit == 0 or v * 0.9 <= num <= v * 1.1 + + nsec_per_sec = 1000000000 + + # With current interface we can't set burst to 0, they will be override + # to bps / 10 and iops / 10. Setting to 1 workarounds this and gets to + # a close effect as no burst, which is good enough for us + limits['bps_max'] = 1 + limits['iops_max'] = 1 + + result = self.vm.qmp("block_set_io_throttle", conv_keys=False, **limits) + self.assert_qmp(result, 'return', {}) + + # Set vm clock to a known value + ns = nsec_per_sec + self.vm.qtest("clock_step %d" % ns) + + # Append more than needed requests into the throttle queue, they should + # drain bps_max and iops_max. + # The remaining requests won't get executed until qtest clock is driven + n = max(limits['iops'], + limits['iops_rd'], + limits['iops_wr'], + limits['bps'] / 512, + limits['bps_rd'] / 512, + limits['bps_wr'] / 512) * seconds + 100 + for i in range(n): + self.vm.hmp_qemu_io("drive0", "aio_read -q 0 512") + self.vm.hmp_qemu_io("drive0", "aio_write -q 0 512") + + start_rd_bytes, start_rd_iops, start_wr_bytes, start_wr_iops = self.blockstats('drive0') + + ns += seconds * nsec_per_sec + self.vm.qtest("clock_step %d" % ns) + # wait for a while to let requests take off + time.sleep(1) + end_rd_bytes, end_rd_iops, end_wr_bytes, end_wr_iops = self.blockstats('drive0') + + # Read and write requests should be processed + assert end_rd_bytes > 0 + assert end_rd_iops > 0 + assert end_wr_bytes > 0 + assert end_wr_iops > 0 + + rd_bytes = end_rd_bytes - start_rd_bytes + rd_iops = end_rd_iops - start_rd_iops + wr_bytes = end_wr_bytes - start_wr_bytes + wr_iops = end_wr_iops - start_wr_iops + + assert check_limit(limits['bps'], rd_bytes + wr_bytes) + assert check_limit(limits['bps_rd'], rd_bytes) + assert check_limit(limits['bps_wr'], wr_bytes) + assert check_limit(limits['iops'], rd_iops + wr_iops) + assert check_limit(limits['iops_rd'], rd_iops) + assert check_limit(limits['iops_wr'], wr_iops) + + def test_bps(self): + self.do_test_throttle(**{ + 'device': 'drive0', + 'bps': 1024, + 'bps_rd': 0, + 'bps_wr': 0, + 'iops': 0, + 'iops_rd': 0, + 'iops_wr': 0, + }) + + def test_bps_rd(self): + self.do_test_throttle(**{ + 'device': 'drive0', + 'bps': 0, + 'bps_rd': 1024, + 'bps_wr': 0, + 'iops': 0, + 'iops_rd': 0, + 'iops_wr': 0, + }) + + def test_bps_wr(self): + self.do_test_throttle(**{ + 'device': 'drive0', + 'bps': 0, + 'bps_rd': 0, + 'bps_wr': 1024, + 'iops': 0, + 'iops_rd': 0, + 'iops_wr': 0, + }) + + def test_iops(self): + self.do_test_throttle(**{ + 'device': 'drive0', + 'bps': 0, + 'bps_rd': 0, + 'bps_wr': 0, + 'iops': 10, + 'iops_rd': 0, + 'iops_wr': 0, + }) + + def test_iops_rd(self): + self.do_test_throttle(**{ + 'device': 'drive0', + 'bps': 0, + 'bps_rd': 0, + 'bps_wr': 0, + 'iops': 0, + 'iops_rd': 10, + 'iops_wr': 0, + }) + + def test_iops_wr(self): + self.do_test_throttle(**{ + 'device': 'drive0', + 'bps': 0, + 'bps_rd': 0, + 'bps_wr': 0, + 'iops': 0, + 'iops_rd': 0, + 'iops_wr': 10, + }) + +if __name__ == '__main__': + iotests.main() diff --git a/tests/qemu-iotests/080.out b/tests/qemu-iotests/080.out new file mode 100644 index 0000000..3f8a935 --- /dev/null +++ b/tests/qemu-iotests/080.out @@ -0,0 +1,5 @@ +...... +---------------------------------------------------------------------- +Ran 6 tests + +OK diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 03c762f..013a7ef 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -82,3 +82,4 @@ 073 rw auto 074 rw auto 077 rw auto +080 rw auto