public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] Clean up patches
@ 2008-10-02 15:05 Steven Rostedt
  2008-10-02 15:05 ` [PATCH 1/5] xen: clean up label Steven Rostedt
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Steven Rostedt @ 2008-10-02 15:05 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrew Morton

Like other kernel developers, I compile kernels several times a day
with various configs. Some are for testing, others are given to me
by others to debug some code.

I like to look at any warnings that gcc gives me, and lately
I've been irritated by the same warnings appearing in the same places
that has nothing to do with my code.

The biggest offender is the Xen code. I figured that I'll take a look at
what these warnings are and if they are trivial, I'll fix them.

The thing that got me when looking into this, is most of the warnings
in Xen come from dead code!  Code that is not called by anyone, or
has references by #if 0 code.

There was one patch from the sound code that only needed a more
robust macro when the debugging was not configured.

The rest of the patches get rid of most of my warnings. There are a
few left where gcc complains about discarding qualifier types but
those are not as trivial to fix, so I'll leave them to those maintainers.

-- Steve


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/5] xen: clean up label
  2008-10-02 15:05 [PATCH 0/5] Clean up patches Steven Rostedt
@ 2008-10-02 15:05 ` Steven Rostedt
  2008-10-02 15:05 ` [PATCH 2/5] xen: remove unused function warnings Steven Rostedt
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Steven Rostedt @ 2008-10-02 15:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Jeremy Fitzhardinge, Chris Wright, Steven Rostedt

[-- Attachment #1: xen-clean-up-patch-site.patch --]
[-- Type: text/plain, Size: 1111 bytes --]

In enlighten.c there's a macro that is defined to jump to a label.
This macro is only used in an ifdef CONFIG_X86_32 section, and the
label is outside that define conditional, which causes warnings.

This patch pushes the label inside the define condition.

CC: Jeremy Fitzhardinge <jeremy@xensource.com>
CC: Chris Wright <chrisw@sous-sol.org>
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
---
 arch/x86/xen/enlighten.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Index: linux-compile.git/arch/x86/xen/enlighten.c
===================================================================
--- linux-compile.git.orig/arch/x86/xen/enlighten.c	2008-09-12 09:18:55.000000000 -0400
+++ linux-compile.git/arch/x86/xen/enlighten.c	2008-10-02 09:38:16.000000000 -0400
@@ -1082,10 +1082,10 @@ static unsigned xen_patch(u8 type, u16 c
 		SITE(pv_irq_ops, irq_disable);
 		SITE(pv_irq_ops, save_fl);
 		SITE(pv_irq_ops, restore_fl);
-#endif /* CONFIG_X86_32 */
-#undef SITE
 
 	patch_site:
+#endif /* CONFIG_X86_32 */
+#undef SITE
 		if (start == NULL || (end-start) > len)
 			goto default_patch;
 

-- 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/5] xen: remove unused function warnings
  2008-10-02 15:05 [PATCH 0/5] Clean up patches Steven Rostedt
  2008-10-02 15:05 ` [PATCH 1/5] xen: clean up label Steven Rostedt
@ 2008-10-02 15:05 ` Steven Rostedt
  2008-10-02 15:05 ` [PATCH 3/5] xen: nuke dead code in enlighten.c Steven Rostedt
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Steven Rostedt @ 2008-10-02 15:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Jeremy Fitzhardinge, Chris Wright, Steven Rostedt

[-- Attachment #1: xen-clean-up-enlight-unused.patch --]
[-- Type: text/plain, Size: 1450 bytes --]

The compiler is complaining that there are unused static functions
in the Xen code. Looking into this, it seems that they are used
but only within #if statements.

This patch matches the functions with the #if statements that they
are referenced by.

CC: Jeremy Fitzhardinge <jeremy@xensource.com>
CC: Chris Wright <chrisw@sous-sol.org>
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
---
 arch/x86/xen/enlighten.c |    4 ++++
 1 file changed, 4 insertions(+)

Index: linux-compile.git/arch/x86/xen/enlighten.c
===================================================================
--- linux-compile.git.orig/arch/x86/xen/enlighten.c	2008-10-02 10:34:13.000000000 -0400
+++ linux-compile.git/arch/x86/xen/enlighten.c	2008-10-02 10:57:52.000000000 -0400
@@ -704,10 +704,12 @@ static unsigned long xen_read_cr2(void)
 	return x86_read_percpu(xen_vcpu)->arch.cr2;
 }
 
+#ifdef CONFIG_X86_32
 static unsigned long xen_read_cr2_direct(void)
 {
 	return x86_read_percpu(xen_vcpu_info.arch.cr2);
 }
+#endif
 
 static void xen_write_cr4(unsigned long cr4)
 {
@@ -962,6 +964,7 @@ static void *xen_kmap_atomic_pte(struct 
 }
 #endif
 
+#ifndef CONFIG_X86_64
 static __init pte_t mask_rw_pte(pte_t *ptep, pte_t pte)
 {
 	/* If there's an existing pte, then don't allow _PAGE_RW to be set */
@@ -980,6 +983,7 @@ static __init void xen_set_pte_init(pte_
 
 	xen_set_pte(ptep, pte);
 }
+#endif
 
 static __init void xen_pagetable_setup_start(pgd_t *base)
 {

-- 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/5] xen: nuke dead code in enlighten.c
  2008-10-02 15:05 [PATCH 0/5] Clean up patches Steven Rostedt
  2008-10-02 15:05 ` [PATCH 1/5] xen: clean up label Steven Rostedt
  2008-10-02 15:05 ` [PATCH 2/5] xen: remove unused function warnings Steven Rostedt
@ 2008-10-02 15:05 ` Steven Rostedt
  2008-10-02 15:05 ` [PATCH 4/5] sound: update snd_assert macro Steven Rostedt
  2008-10-02 15:05 ` [PATCH 5/5] xen: nuke the ballon files Steven Rostedt
  4 siblings, 0 replies; 10+ messages in thread
From: Steven Rostedt @ 2008-10-02 15:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Jeremy Fitzhardinge, Chris Wright, Steven Rostedt

[-- Attachment #1: xen-nuke-enlighten-dead-code.patch --]
[-- Type: text/plain, Size: 2268 bytes --]

The kernel is no place to hold dead code.

No reason for #if 0 in the kernel proper.

Note, the walk function being deleted is only referenced in the
 #if 0 code.

CC: Jeremy Fitzhardinge <jeremy@xensource.com>
CC: Chris Wright <chrisw@sous-sol.org>
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
---
 arch/x86/xen/enlighten.c |   42 ------------------------------------------
 1 file changed, 42 deletions(-)

Index: linux-compile.git/arch/x86/xen/enlighten.c
===================================================================
--- linux-compile.git.orig/arch/x86/xen/enlighten.c	2008-10-02 10:34:41.000000000 -0400
+++ linux-compile.git/arch/x86/xen/enlighten.c	2008-10-02 10:34:59.000000000 -0400
@@ -1451,39 +1451,6 @@ static void *m2v(phys_addr_t maddr)
 	return __ka(m2p(maddr));
 }
 
-#ifdef CONFIG_X86_64
-static void walk(pgd_t *pgd, unsigned long addr)
-{
-	unsigned l4idx = pgd_index(addr);
-	unsigned l3idx = pud_index(addr);
-	unsigned l2idx = pmd_index(addr);
-	unsigned l1idx = pte_index(addr);
-	pgd_t l4;
-	pud_t l3;
-	pmd_t l2;
-	pte_t l1;
-
-	xen_raw_printk("walk %p, %lx -> %d %d %d %d\n",
-		       pgd, addr, l4idx, l3idx, l2idx, l1idx);
-
-	l4 = pgd[l4idx];
-	xen_raw_printk("  l4: %016lx\n", l4.pgd);
-	xen_raw_printk("      %016lx\n", pgd_val(l4));
-
-	l3 = ((pud_t *)(m2v(l4.pgd)))[l3idx];
-	xen_raw_printk("  l3: %016lx\n", l3.pud);
-	xen_raw_printk("      %016lx\n", pud_val(l3));
-
-	l2 = ((pmd_t *)(m2v(l3.pud)))[l2idx];
-	xen_raw_printk("  l2: %016lx\n", l2.pmd);
-	xen_raw_printk("      %016lx\n", pmd_val(l2));
-
-	l1 = ((pte_t *)(m2v(l2.pmd)))[l1idx];
-	xen_raw_printk("  l1: %016lx\n", l1.pte);
-	xen_raw_printk("      %016lx\n", pte_val(l1));
-}
-#endif
-
 static void set_page_prot(void *addr, pgprot_t prot)
 {
 	unsigned long pfn = __pa(addr) >> PAGE_SHIFT;
@@ -1747,15 +1714,6 @@ asmlinkage void __init xen_start_kernel(
 
 	xen_raw_console_write("about to get started...\n");
 
-#if 0
-	xen_raw_printk("&boot_params=%p __pa(&boot_params)=%lx __va(__pa(&boot_params))=%lx\n",
-		       &boot_params, __pa_symbol(&boot_params),
-		       __va(__pa_symbol(&boot_params)));
-
-	walk(pgd, &boot_params);
-	walk(pgd, __va(__pa(&boot_params)));
-#endif
-
 	/* Start the world */
 #ifdef CONFIG_X86_32
 	i386_start_kernel();

-- 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 4/5] sound: update snd_assert macro
  2008-10-02 15:05 [PATCH 0/5] Clean up patches Steven Rostedt
                   ` (2 preceding siblings ...)
  2008-10-02 15:05 ` [PATCH 3/5] xen: nuke dead code in enlighten.c Steven Rostedt
@ 2008-10-02 15:05 ` Steven Rostedt
  2008-10-03  9:10   ` Takashi Iwai
  2008-10-02 15:05 ` [PATCH 5/5] xen: nuke the ballon files Steven Rostedt
  4 siblings, 1 reply; 10+ messages in thread
From: Steven Rostedt @ 2008-10-02 15:05 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrew Morton, Jaroslav Kysela, Steven Rostedt

[-- Attachment #1: sound-core-fix-snd-assert-macro.patch --]
[-- Type: text/plain, Size: 1145 bytes --]

One user of the snd_assert macro calls a goto and the compiler
complains that the label is not used when the snd_assert is
not set.

This patch makes snd_assert more robust when not defined to
let the compiler know about arguments when not in use.

CC: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
---
 include/sound/core.h |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Index: linux-compile.git/include/sound/core.h
===================================================================
--- linux-compile.git.orig/include/sound/core.h	2008-07-27 09:26:33.000000000 -0400
+++ linux-compile.git/include/sound/core.h	2008-10-02 10:00:57.000000000 -0400
@@ -407,7 +407,13 @@ void snd_verbose_printd(const char *file
 #else /* !CONFIG_SND_DEBUG */
 
 #define snd_printd(fmt, args...)	/* nothing */
-#define snd_assert(expr, args...)	(void)(expr)
+/* Keep the compiler happy by showing the expr and args */
+#define snd_assert(expr, args...)	do {	\
+	if (0) {				\
+		(void)(expr);			\
+		args;				\
+	}					\
+} while(0)
 #define snd_BUG()			/* nothing */
 
 #endif /* CONFIG_SND_DEBUG */

-- 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 5/5] xen: nuke the ballon files
  2008-10-02 15:05 [PATCH 0/5] Clean up patches Steven Rostedt
                   ` (3 preceding siblings ...)
  2008-10-02 15:05 ` [PATCH 4/5] sound: update snd_assert macro Steven Rostedt
@ 2008-10-02 15:05 ` Steven Rostedt
  2008-10-02 15:34   ` Jeremy Fitzhardinge
  4 siblings, 1 reply; 10+ messages in thread
From: Steven Rostedt @ 2008-10-02 15:05 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Jeremy Fitzhardinge, Chris Wright, Steven Rostedt

[-- Attachment #1: xen-nuke-balloon.patch --]
[-- Type: text/plain, Size: 23393 bytes --]

Investigating the unused static files in the balloon code, I discovered
that the balloon code is not used at all.

The header file is one big #if 0 and all the functions in the C file
is static. There is no caller like init_module to hook to any of
these functions. Basically, this code is one big patch of dead code
wasting space on my hard drive.

This patch removes the balloon code altogether since there are no
users.

CC: Jeremy Fitzhardinge <jeremy@xensource.com>
CC: Chris Wright <chrisw@sous-sol.org>
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
---
 drivers/xen/Makefile  |    1 
 drivers/xen/balloon.c |  713 --------------------------------------------------
 include/xen/balloon.h |   61 ----
 3 files changed, 775 deletions(-)

Index: linux-compile.git/drivers/xen/Makefile
===================================================================
--- linux-compile.git.orig/drivers/xen/Makefile	2008-10-02 10:33:57.000000000 -0400
+++ linux-compile.git/drivers/xen/Makefile	2008-10-02 10:35:02.000000000 -0400
@@ -1,4 +1,3 @@
 obj-y	+= grant-table.o features.o events.o manage.o
 obj-y	+= xenbus/
 obj-$(CONFIG_XEN_XENCOMM)	+= xencomm.o
-obj-$(CONFIG_XEN_BALLOON)	+= balloon.o
Index: linux-compile.git/drivers/xen/balloon.c
===================================================================
--- linux-compile.git.orig/drivers/xen/balloon.c	2008-10-02 10:33:57.000000000 -0400
+++ /dev/null	1970-01-01 00:00:00.000000000 +0000
@@ -1,713 +0,0 @@
-/******************************************************************************
- * balloon.c
- *
- * Xen balloon driver - enables returning/claiming memory to/from Xen.
- *
- * Copyright (c) 2003, B Dragovic
- * Copyright (c) 2003-2004, M Williamson, K Fraser
- * Copyright (c) 2005 Dan M. Smith, IBM Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation; or, when distributed
- * separately from the Linux kernel or incorporated into other
- * software packages, subject to the following license:
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this source file (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use, copy, modify,
- * merge, publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/sched.h>
-#include <linux/errno.h>
-#include <linux/mm.h>
-#include <linux/bootmem.h>
-#include <linux/pagemap.h>
-#include <linux/highmem.h>
-#include <linux/mutex.h>
-#include <linux/highmem.h>
-#include <linux/list.h>
-#include <linux/sysdev.h>
-
-#include <asm/xen/hypervisor.h>
-#include <asm/page.h>
-#include <asm/pgalloc.h>
-#include <asm/pgtable.h>
-#include <asm/uaccess.h>
-#include <asm/tlb.h>
-
-#include <xen/interface/memory.h>
-#include <xen/balloon.h>
-#include <xen/xenbus.h>
-#include <xen/features.h>
-#include <xen/page.h>
-
-#define PAGES2KB(_p) ((_p)<<(PAGE_SHIFT-10))
-
-#define BALLOON_CLASS_NAME "xen_memory"
-
-struct balloon_stats {
-	/* We aim for 'current allocation' == 'target allocation'. */
-	unsigned long current_pages;
-	unsigned long target_pages;
-	/* We may hit the hard limit in Xen. If we do then we remember it. */
-	unsigned long hard_limit;
-	/*
-	 * Drivers may alter the memory reservation independently, but they
-	 * must inform the balloon driver so we avoid hitting the hard limit.
-	 */
-	unsigned long driver_pages;
-	/* Number of pages in high- and low-memory balloons. */
-	unsigned long balloon_low;
-	unsigned long balloon_high;
-};
-
-static DEFINE_MUTEX(balloon_mutex);
-
-static struct sys_device balloon_sysdev;
-
-static int register_balloon(struct sys_device *sysdev);
-
-/*
- * Protects atomic reservation decrease/increase against concurrent increases.
- * Also protects non-atomic updates of current_pages and driver_pages, and
- * balloon lists.
- */
-static DEFINE_SPINLOCK(balloon_lock);
-
-static struct balloon_stats balloon_stats;
-
-/* We increase/decrease in batches which fit in a page */
-static unsigned long frame_list[PAGE_SIZE / sizeof(unsigned long)];
-
-/* VM /proc information for memory */
-extern unsigned long totalram_pages;
-
-#ifdef CONFIG_HIGHMEM
-extern unsigned long totalhigh_pages;
-#define inc_totalhigh_pages() (totalhigh_pages++)
-#define dec_totalhigh_pages() (totalhigh_pages--)
-#else
-#define inc_totalhigh_pages() do {} while(0)
-#define dec_totalhigh_pages() do {} while(0)
-#endif
-
-/* List of ballooned pages, threaded through the mem_map array. */
-static LIST_HEAD(ballooned_pages);
-
-/* Main work function, always executed in process context. */
-static void balloon_process(struct work_struct *work);
-static DECLARE_WORK(balloon_worker, balloon_process);
-static struct timer_list balloon_timer;
-
-/* When ballooning out (allocating memory to return to Xen) we don't really
-   want the kernel to try too hard since that can trigger the oom killer. */
-#define GFP_BALLOON \
-	(GFP_HIGHUSER | __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC)
-
-static void scrub_page(struct page *page)
-{
-#ifdef CONFIG_XEN_SCRUB_PAGES
-	if (PageHighMem(page)) {
-		void *v = kmap(page);
-		clear_page(v);
-		kunmap(v);
-	} else {
-		void *v = page_address(page);
-		clear_page(v);
-	}
-#endif
-}
-
-/* balloon_append: add the given page to the balloon. */
-static void balloon_append(struct page *page)
-{
-	/* Lowmem is re-populated first, so highmem pages go at list tail. */
-	if (PageHighMem(page)) {
-		list_add_tail(&page->lru, &ballooned_pages);
-		balloon_stats.balloon_high++;
-		dec_totalhigh_pages();
-	} else {
-		list_add(&page->lru, &ballooned_pages);
-		balloon_stats.balloon_low++;
-	}
-}
-
-/* balloon_retrieve: rescue a page from the balloon, if it is not empty. */
-static struct page *balloon_retrieve(void)
-{
-	struct page *page;
-
-	if (list_empty(&ballooned_pages))
-		return NULL;
-
-	page = list_entry(ballooned_pages.next, struct page, lru);
-	list_del(&page->lru);
-
-	if (PageHighMem(page)) {
-		balloon_stats.balloon_high--;
-		inc_totalhigh_pages();
-	}
-	else
-		balloon_stats.balloon_low--;
-
-	return page;
-}
-
-static struct page *balloon_first_page(void)
-{
-	if (list_empty(&ballooned_pages))
-		return NULL;
-	return list_entry(ballooned_pages.next, struct page, lru);
-}
-
-static struct page *balloon_next_page(struct page *page)
-{
-	struct list_head *next = page->lru.next;
-	if (next == &ballooned_pages)
-		return NULL;
-	return list_entry(next, struct page, lru);
-}
-
-static void balloon_alarm(unsigned long unused)
-{
-	schedule_work(&balloon_worker);
-}
-
-static unsigned long current_target(void)
-{
-	unsigned long target = min(balloon_stats.target_pages, balloon_stats.hard_limit);
-
-	target = min(target,
-		     balloon_stats.current_pages +
-		     balloon_stats.balloon_low +
-		     balloon_stats.balloon_high);
-
-	return target;
-}
-
-static int increase_reservation(unsigned long nr_pages)
-{
-	unsigned long  pfn, i, flags;
-	struct page   *page;
-	long           rc;
-	struct xen_memory_reservation reservation = {
-		.address_bits = 0,
-		.extent_order = 0,
-		.domid        = DOMID_SELF
-	};
-
-	if (nr_pages > ARRAY_SIZE(frame_list))
-		nr_pages = ARRAY_SIZE(frame_list);
-
-	spin_lock_irqsave(&balloon_lock, flags);
-
-	page = balloon_first_page();
-	for (i = 0; i < nr_pages; i++) {
-		BUG_ON(page == NULL);
-		frame_list[i] = page_to_pfn(page);;
-		page = balloon_next_page(page);
-	}
-
-	set_xen_guest_handle(reservation.extent_start, frame_list);
-	reservation.nr_extents   = nr_pages;
-	rc = HYPERVISOR_memory_op(
-		XENMEM_populate_physmap, &reservation);
-	if (rc < nr_pages) {
-		if (rc > 0) {
-			int ret;
-
-			/* We hit the Xen hard limit: reprobe. */
-			reservation.nr_extents = rc;
-			ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
-					&reservation);
-			BUG_ON(ret != rc);
-		}
-		if (rc >= 0)
-			balloon_stats.hard_limit = (balloon_stats.current_pages + rc -
-						    balloon_stats.driver_pages);
-		goto out;
-	}
-
-	for (i = 0; i < nr_pages; i++) {
-		page = balloon_retrieve();
-		BUG_ON(page == NULL);
-
-		pfn = page_to_pfn(page);
-		BUG_ON(!xen_feature(XENFEAT_auto_translated_physmap) &&
-		       phys_to_machine_mapping_valid(pfn));
-
-		set_phys_to_machine(pfn, frame_list[i]);
-
-		/* Link back into the page tables if not highmem. */
-		if (pfn < max_low_pfn) {
-			int ret;
-			ret = HYPERVISOR_update_va_mapping(
-				(unsigned long)__va(pfn << PAGE_SHIFT),
-				mfn_pte(frame_list[i], PAGE_KERNEL),
-				0);
-			BUG_ON(ret);
-		}
-
-		/* Relinquish the page back to the allocator. */
-		ClearPageReserved(page);
-		init_page_count(page);
-		__free_page(page);
-	}
-
-	balloon_stats.current_pages += nr_pages;
-	totalram_pages = balloon_stats.current_pages;
-
- out:
-	spin_unlock_irqrestore(&balloon_lock, flags);
-
-	return 0;
-}
-
-static int decrease_reservation(unsigned long nr_pages)
-{
-	unsigned long  pfn, i, flags;
-	struct page   *page;
-	int            need_sleep = 0;
-	int ret;
-	struct xen_memory_reservation reservation = {
-		.address_bits = 0,
-		.extent_order = 0,
-		.domid        = DOMID_SELF
-	};
-
-	if (nr_pages > ARRAY_SIZE(frame_list))
-		nr_pages = ARRAY_SIZE(frame_list);
-
-	for (i = 0; i < nr_pages; i++) {
-		if ((page = alloc_page(GFP_BALLOON)) == NULL) {
-			nr_pages = i;
-			need_sleep = 1;
-			break;
-		}
-
-		pfn = page_to_pfn(page);
-		frame_list[i] = pfn_to_mfn(pfn);
-
-		scrub_page(page);
-	}
-
-	/* Ensure that ballooned highmem pages don't have kmaps. */
-	kmap_flush_unused();
-	flush_tlb_all();
-
-	spin_lock_irqsave(&balloon_lock, flags);
-
-	/* No more mappings: invalidate P2M and add to balloon. */
-	for (i = 0; i < nr_pages; i++) {
-		pfn = mfn_to_pfn(frame_list[i]);
-		set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
-		balloon_append(pfn_to_page(pfn));
-	}
-
-	set_xen_guest_handle(reservation.extent_start, frame_list);
-	reservation.nr_extents   = nr_pages;
-	ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
-	BUG_ON(ret != nr_pages);
-
-	balloon_stats.current_pages -= nr_pages;
-	totalram_pages = balloon_stats.current_pages;
-
-	spin_unlock_irqrestore(&balloon_lock, flags);
-
-	return need_sleep;
-}
-
-/*
- * We avoid multiple worker processes conflicting via the balloon mutex.
- * We may of course race updates of the target counts (which are protected
- * by the balloon lock), or with changes to the Xen hard limit, but we will
- * recover from these in time.
- */
-static void balloon_process(struct work_struct *work)
-{
-	int need_sleep = 0;
-	long credit;
-
-	mutex_lock(&balloon_mutex);
-
-	do {
-		credit = current_target() - balloon_stats.current_pages;
-		if (credit > 0)
-			need_sleep = (increase_reservation(credit) != 0);
-		if (credit < 0)
-			need_sleep = (decrease_reservation(-credit) != 0);
-
-#ifndef CONFIG_PREEMPT
-		if (need_resched())
-			schedule();
-#endif
-	} while ((credit != 0) && !need_sleep);
-
-	/* Schedule more work if there is some still to be done. */
-	if (current_target() != balloon_stats.current_pages)
-		mod_timer(&balloon_timer, jiffies + HZ);
-
-	mutex_unlock(&balloon_mutex);
-}
-
-/* Resets the Xen limit, sets new target, and kicks off processing. */
-static void balloon_set_new_target(unsigned long target)
-{
-	/* No need for lock. Not read-modify-write updates. */
-	balloon_stats.hard_limit   = ~0UL;
-	balloon_stats.target_pages = target;
-	schedule_work(&balloon_worker);
-}
-
-static struct xenbus_watch target_watch =
-{
-	.node = "memory/target"
-};
-
-/* React to a change in the target key */
-static void watch_target(struct xenbus_watch *watch,
-			 const char **vec, unsigned int len)
-{
-	unsigned long long new_target;
-	int err;
-
-	err = xenbus_scanf(XBT_NIL, "memory", "target", "%llu", &new_target);
-	if (err != 1) {
-		/* This is ok (for domain0 at least) - so just return */
-		return;
-	}
-
-	/* The given memory/target value is in KiB, so it needs converting to
-	 * pages. PAGE_SHIFT converts bytes to pages, hence PAGE_SHIFT - 10.
-	 */
-	balloon_set_new_target(new_target >> (PAGE_SHIFT - 10));
-}
-
-static int balloon_init_watcher(struct notifier_block *notifier,
-				unsigned long event,
-				void *data)
-{
-	int err;
-
-	err = register_xenbus_watch(&target_watch);
-	if (err)
-		printk(KERN_ERR "Failed to set balloon watcher\n");
-
-	return NOTIFY_DONE;
-}
-
-static struct notifier_block xenstore_notifier;
-
-static int __init balloon_init(void)
-{
-	unsigned long pfn;
-	struct page *page;
-
-	if (!is_running_on_xen())
-		return -ENODEV;
-
-	pr_info("xen_balloon: Initialising balloon driver.\n");
-
-	balloon_stats.current_pages = min(xen_start_info->nr_pages, max_pfn);
-	totalram_pages   = balloon_stats.current_pages;
-	balloon_stats.target_pages  = balloon_stats.current_pages;
-	balloon_stats.balloon_low   = 0;
-	balloon_stats.balloon_high  = 0;
-	balloon_stats.driver_pages  = 0UL;
-	balloon_stats.hard_limit    = ~0UL;
-
-	init_timer(&balloon_timer);
-	balloon_timer.data = 0;
-	balloon_timer.function = balloon_alarm;
-
-	register_balloon(&balloon_sysdev);
-
-	/* Initialise the balloon with excess memory space. */
-	for (pfn = xen_start_info->nr_pages; pfn < max_pfn; pfn++) {
-		page = pfn_to_page(pfn);
-		if (!PageReserved(page))
-			balloon_append(page);
-	}
-
-	target_watch.callback = watch_target;
-	xenstore_notifier.notifier_call = balloon_init_watcher;
-
-	register_xenstore_notifier(&xenstore_notifier);
-
-	return 0;
-}
-
-subsys_initcall(balloon_init);
-
-static void balloon_exit(void)
-{
-    /* XXX - release balloon here */
-    return;
-}
-
-module_exit(balloon_exit);
-
-static void balloon_update_driver_allowance(long delta)
-{
-	unsigned long flags;
-
-	spin_lock_irqsave(&balloon_lock, flags);
-	balloon_stats.driver_pages += delta;
-	spin_unlock_irqrestore(&balloon_lock, flags);
-}
-
-static int dealloc_pte_fn(
-	pte_t *pte, struct page *pmd_page, unsigned long addr, void *data)
-{
-	unsigned long mfn = pte_mfn(*pte);
-	int ret;
-	struct xen_memory_reservation reservation = {
-		.nr_extents   = 1,
-		.extent_order = 0,
-		.domid        = DOMID_SELF
-	};
-	set_xen_guest_handle(reservation.extent_start, &mfn);
-	set_pte_at(&init_mm, addr, pte, __pte_ma(0ull));
-	set_phys_to_machine(__pa(addr) >> PAGE_SHIFT, INVALID_P2M_ENTRY);
-	ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
-	BUG_ON(ret != 1);
-	return 0;
-}
-
-static struct page **alloc_empty_pages_and_pagevec(int nr_pages)
-{
-	unsigned long vaddr, flags;
-	struct page *page, **pagevec;
-	int i, ret;
-
-	pagevec = kmalloc(sizeof(page) * nr_pages, GFP_KERNEL);
-	if (pagevec == NULL)
-		return NULL;
-
-	for (i = 0; i < nr_pages; i++) {
-		page = pagevec[i] = alloc_page(GFP_KERNEL);
-		if (page == NULL)
-			goto err;
-
-		vaddr = (unsigned long)page_address(page);
-
-		scrub_page(page);
-
-		spin_lock_irqsave(&balloon_lock, flags);
-
-		if (xen_feature(XENFEAT_auto_translated_physmap)) {
-			unsigned long gmfn = page_to_pfn(page);
-			struct xen_memory_reservation reservation = {
-				.nr_extents   = 1,
-				.extent_order = 0,
-				.domid        = DOMID_SELF
-			};
-			set_xen_guest_handle(reservation.extent_start, &gmfn);
-			ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
-						   &reservation);
-			if (ret == 1)
-				ret = 0; /* success */
-		} else {
-			ret = apply_to_page_range(&init_mm, vaddr, PAGE_SIZE,
-						  dealloc_pte_fn, NULL);
-		}
-
-		if (ret != 0) {
-			spin_unlock_irqrestore(&balloon_lock, flags);
-			__free_page(page);
-			goto err;
-		}
-
-		totalram_pages = --balloon_stats.current_pages;
-
-		spin_unlock_irqrestore(&balloon_lock, flags);
-	}
-
- out:
-	schedule_work(&balloon_worker);
-	flush_tlb_all();
-	return pagevec;
-
- err:
-	spin_lock_irqsave(&balloon_lock, flags);
-	while (--i >= 0)
-		balloon_append(pagevec[i]);
-	spin_unlock_irqrestore(&balloon_lock, flags);
-	kfree(pagevec);
-	pagevec = NULL;
-	goto out;
-}
-
-static void free_empty_pages_and_pagevec(struct page **pagevec, int nr_pages)
-{
-	unsigned long flags;
-	int i;
-
-	if (pagevec == NULL)
-		return;
-
-	spin_lock_irqsave(&balloon_lock, flags);
-	for (i = 0; i < nr_pages; i++) {
-		BUG_ON(page_count(pagevec[i]) != 1);
-		balloon_append(pagevec[i]);
-	}
-	spin_unlock_irqrestore(&balloon_lock, flags);
-
-	kfree(pagevec);
-
-	schedule_work(&balloon_worker);
-}
-
-static void balloon_release_driver_page(struct page *page)
-{
-	unsigned long flags;
-
-	spin_lock_irqsave(&balloon_lock, flags);
-	balloon_append(page);
-	balloon_stats.driver_pages--;
-	spin_unlock_irqrestore(&balloon_lock, flags);
-
-	schedule_work(&balloon_worker);
-}
-
-
-#define BALLOON_SHOW(name, format, args...)			\
-	static ssize_t show_##name(struct sys_device *dev,	\
-				   char *buf)			\
-	{							\
-		return sprintf(buf, format, ##args);		\
-	}							\
-	static SYSDEV_ATTR(name, S_IRUGO, show_##name, NULL)
-
-BALLOON_SHOW(current_kb, "%lu\n", PAGES2KB(balloon_stats.current_pages));
-BALLOON_SHOW(low_kb, "%lu\n", PAGES2KB(balloon_stats.balloon_low));
-BALLOON_SHOW(high_kb, "%lu\n", PAGES2KB(balloon_stats.balloon_high));
-BALLOON_SHOW(hard_limit_kb,
-	     (balloon_stats.hard_limit!=~0UL) ? "%lu\n" : "???\n",
-	     (balloon_stats.hard_limit!=~0UL) ? PAGES2KB(balloon_stats.hard_limit) : 0);
-BALLOON_SHOW(driver_kb, "%lu\n", PAGES2KB(balloon_stats.driver_pages));
-
-static ssize_t show_target_kb(struct sys_device *dev, char *buf)
-{
-	return sprintf(buf, "%lu\n", PAGES2KB(balloon_stats.target_pages));
-}
-
-static ssize_t store_target_kb(struct sys_device *dev,
-			       struct sysdev_attribute *attr,
-			       const char *buf,
-			       size_t count)
-{
-	char memstring[64], *endchar;
-	unsigned long long target_bytes;
-
-	if (!capable(CAP_SYS_ADMIN))
-		return -EPERM;
-
-	if (count <= 1)
-		return -EBADMSG; /* runt */
-	if (count > sizeof(memstring))
-		return -EFBIG;   /* too long */
-	strcpy(memstring, buf);
-
-	target_bytes = memparse(memstring, &endchar);
-	balloon_set_new_target(target_bytes >> PAGE_SHIFT);
-
-	return count;
-}
-
-static SYSDEV_ATTR(target_kb, S_IRUGO | S_IWUSR,
-		   show_target_kb, store_target_kb);
-
-static struct sysdev_attribute *balloon_attrs[] = {
-	&attr_target_kb,
-};
-
-static struct attribute *balloon_info_attrs[] = {
-	&attr_current_kb.attr,
-	&attr_low_kb.attr,
-	&attr_high_kb.attr,
-	&attr_hard_limit_kb.attr,
-	&attr_driver_kb.attr,
-	NULL
-};
-
-static struct attribute_group balloon_info_group = {
-	.name = "info",
-	.attrs = balloon_info_attrs,
-};
-
-static struct sysdev_class balloon_sysdev_class = {
-	.name = BALLOON_CLASS_NAME,
-};
-
-static int register_balloon(struct sys_device *sysdev)
-{
-	int i, error;
-
-	error = sysdev_class_register(&balloon_sysdev_class);
-	if (error)
-		return error;
-
-	sysdev->id = 0;
-	sysdev->cls = &balloon_sysdev_class;
-
-	error = sysdev_register(sysdev);
-	if (error) {
-		sysdev_class_unregister(&balloon_sysdev_class);
-		return error;
-	}
-
-	for (i = 0; i < ARRAY_SIZE(balloon_attrs); i++) {
-		error = sysdev_create_file(sysdev, balloon_attrs[i]);
-		if (error)
-			goto fail;
-	}
-
-	error = sysfs_create_group(&sysdev->kobj, &balloon_info_group);
-	if (error)
-		goto fail;
-
-	return 0;
-
- fail:
-	while (--i >= 0)
-		sysdev_remove_file(sysdev, balloon_attrs[i]);
-	sysdev_unregister(sysdev);
-	sysdev_class_unregister(&balloon_sysdev_class);
-	return error;
-}
-
-static void unregister_balloon(struct sys_device *sysdev)
-{
-	int i;
-
-	sysfs_remove_group(&sysdev->kobj, &balloon_info_group);
-	for (i = 0; i < ARRAY_SIZE(balloon_attrs); i++)
-		sysdev_remove_file(sysdev, balloon_attrs[i]);
-	sysdev_unregister(sysdev);
-	sysdev_class_unregister(&balloon_sysdev_class);
-}
-
-static void balloon_sysfs_exit(void)
-{
-	unregister_balloon(&balloon_sysdev);
-}
-
-MODULE_LICENSE("GPL");
Index: linux-compile.git/include/xen/balloon.h
===================================================================
--- linux-compile.git.orig/include/xen/balloon.h	2008-10-02 10:33:57.000000000 -0400
+++ /dev/null	1970-01-01 00:00:00.000000000 +0000
@@ -1,61 +0,0 @@
-/******************************************************************************
- * balloon.h
- *
- * Xen balloon driver - enables returning/claiming memory to/from Xen.
- *
- * Copyright (c) 2003, B Dragovic
- * Copyright (c) 2003-2004, M Williamson, K Fraser
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation; or, when distributed
- * separately from the Linux kernel or incorporated into other
- * software packages, subject to the following license:
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this source file (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use, copy, modify,
- * merge, publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-#ifndef __XEN_BALLOON_H__
-#define __XEN_BALLOON_H__
-
-#include <linux/spinlock.h>
-
-#if 0
-/*
- * Inform the balloon driver that it should allow some slop for device-driver
- * memory activities.
- */
-void balloon_update_driver_allowance(long delta);
-
-/* Allocate/free a set of empty pages in low memory (i.e., no RAM mapped). */
-struct page **alloc_empty_pages_and_pagevec(int nr_pages);
-void free_empty_pages_and_pagevec(struct page **pagevec, int nr_pages);
-
-void balloon_release_driver_page(struct page *page);
-
-/*
- * Prevent the balloon driver from changing the memory reservation during
- * a driver critical region.
- */
-extern spinlock_t balloon_lock;
-#define balloon_lock(__flags)   spin_lock_irqsave(&balloon_lock, __flags)
-#define balloon_unlock(__flags) spin_unlock_irqrestore(&balloon_lock, __flags)
-#endif
-
-#endif /* __XEN_BALLOON_H__ */

-- 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 5/5] xen: nuke the ballon files
  2008-10-02 15:05 ` [PATCH 5/5] xen: nuke the ballon files Steven Rostedt
@ 2008-10-02 15:34   ` Jeremy Fitzhardinge
  2008-10-02 17:59     ` Steven Rostedt
  0 siblings, 1 reply; 10+ messages in thread
From: Jeremy Fitzhardinge @ 2008-10-02 15:34 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: linux-kernel, Andrew Morton, Jeremy Fitzhardinge, Chris Wright,
	Steven Rostedt

Steven Rostedt wrote:
> Investigating the unused static files in the balloon code, I discovered
> that the balloon code is not used at all.
>
> The header file is one big #if 0 and all the functions in the C file
> is static. There is no caller like init_module to hook to any of
> these functions. Basically, this code is one big patch of dead code
> wasting space on my hard drive.
>
> This patch removes the balloon code altogether since there are no
> users.
>   

Er, I think you should back away from that crack pipe.

> -subsys_initcall(balloon_init);

    J

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 5/5] xen: nuke the ballon files
  2008-10-02 15:34   ` Jeremy Fitzhardinge
@ 2008-10-02 17:59     ` Steven Rostedt
  0 siblings, 0 replies; 10+ messages in thread
From: Steven Rostedt @ 2008-10-02 17:59 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: linux-kernel, Andrew Morton, Jeremy Fitzhardinge, Chris Wright,
	Steven Rostedt


On Thu, 2 Oct 2008, Jeremy Fitzhardinge wrote:

> Steven Rostedt wrote:
> > Investigating the unused static files in the balloon code, I discovered
> > that the balloon code is not used at all.
> > 
> > The header file is one big #if 0 and all the functions in the C file
> > is static. There is no caller like init_module to hook to any of
> > these functions. Basically, this code is one big patch of dead code
> > wasting space on my hard drive.
> > 
> > This patch removes the balloon code altogether since there are no
> > users.
> >   
> 
> Er, I think you should back away from that crack pipe.

No, coffee is my drug of choice. I did have a bit of overdose today ;-)

> 
> > -subsys_initcall(balloon_init);

Ouch! How did I miss that.

Anyway, there are still a bunch of functions in that code that are not 
referenced.  OK, nack this patch, but could you please supply one that 
cleans that code up.

Thanks,

-- Steve


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 4/5] sound: update snd_assert macro
  2008-10-02 15:05 ` [PATCH 4/5] sound: update snd_assert macro Steven Rostedt
@ 2008-10-03  9:10   ` Takashi Iwai
  2008-10-03 14:24     ` Steven Rostedt
  0 siblings, 1 reply; 10+ messages in thread
From: Takashi Iwai @ 2008-10-03  9:10 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: linux-kernel, Andrew Morton, Jaroslav Kysela, Steven Rostedt

At Thu, 02 Oct 2008 11:05:33 -0400,
Steven Rostedt wrote:
> 
> One user of the snd_assert macro calls a goto and the compiler
> complains that the label is not used when the snd_assert is
> not set.
> 
> This patch makes snd_assert more robust when not defined to
> let the compiler know about arguments when not in use.

This issue was already fixed differently in the recent ALSA tree
(thus in linux-next tree as well).

thanks,

Takashi


> 
> CC: Jaroslav Kysela <perex@perex.cz>
> Signed-off-by: Steven Rostedt <srostedt@redhat.com>
> ---
>  include/sound/core.h |    8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> Index: linux-compile.git/include/sound/core.h
> ===================================================================
> --- linux-compile.git.orig/include/sound/core.h	2008-07-27 09:26:33.000000000 -0400
> +++ linux-compile.git/include/sound/core.h	2008-10-02 10:00:57.000000000 -0400
> @@ -407,7 +407,13 @@ void snd_verbose_printd(const char *file
>  #else /* !CONFIG_SND_DEBUG */
>  
>  #define snd_printd(fmt, args...)	/* nothing */
> -#define snd_assert(expr, args...)	(void)(expr)
> +/* Keep the compiler happy by showing the expr and args */
> +#define snd_assert(expr, args...)	do {	\
> +	if (0) {				\
> +		(void)(expr);			\
> +		args;				\
> +	}					\
> +} while(0)
>  #define snd_BUG()			/* nothing */
>  
>  #endif /* CONFIG_SND_DEBUG */
> 
> -- 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 4/5] sound: update snd_assert macro
  2008-10-03  9:10   ` Takashi Iwai
@ 2008-10-03 14:24     ` Steven Rostedt
  0 siblings, 0 replies; 10+ messages in thread
From: Steven Rostedt @ 2008-10-03 14:24 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: linux-kernel, Andrew Morton, Jaroslav Kysela, Steven Rostedt


On Fri, 3 Oct 2008, Takashi Iwai wrote:

> At Thu, 02 Oct 2008 11:05:33 -0400,
> Steven Rostedt wrote:
> > 
> > One user of the snd_assert macro calls a goto and the compiler
> > complains that the label is not used when the snd_assert is
> > not set.
> > 
> > This patch makes snd_assert more robust when not defined to
> > let the compiler know about arguments when not in use.
> 
> This issue was already fixed differently in the recent ALSA tree
> (thus in linux-next tree as well).
> 

So it seems.

Thanks,

-- Steve


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-10-03 14:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-02 15:05 [PATCH 0/5] Clean up patches Steven Rostedt
2008-10-02 15:05 ` [PATCH 1/5] xen: clean up label Steven Rostedt
2008-10-02 15:05 ` [PATCH 2/5] xen: remove unused function warnings Steven Rostedt
2008-10-02 15:05 ` [PATCH 3/5] xen: nuke dead code in enlighten.c Steven Rostedt
2008-10-02 15:05 ` [PATCH 4/5] sound: update snd_assert macro Steven Rostedt
2008-10-03  9:10   ` Takashi Iwai
2008-10-03 14:24     ` Steven Rostedt
2008-10-02 15:05 ` [PATCH 5/5] xen: nuke the ballon files Steven Rostedt
2008-10-02 15:34   ` Jeremy Fitzhardinge
2008-10-02 17:59     ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox