All of lore.kernel.org
 help / color / mirror / Atom feed
From: William Lee Irwin III <wli@holomorphy.com>
To: linux-kernel@vger.kernel.org, rddunlap@osdl.org
Subject: Re: [profile]: [22/23] put 1 << prof_shift at prof_buffer[0]
Date: Tue, 22 Jun 2004 10:12:07 -0700	[thread overview]
Message-ID: <20040622171207.GE2135@holomorphy.com> (raw)
In-Reply-To: <20040622171057.GD2135@holomorphy.com>

On Tue, Jun 22, 2004 at 10:10:57AM -0700, William Lee Irwin III wrote:
> And this actually needs to be the following, to fix up an off-by-one
> and a hunk that migrated to the wrong patch of the series (to be
> followed by an mmap() patch that actually applies atop this):

And the mmap() patch that applies atop this is:


Index: prof-2.6.7/kernel/profile.c
===================================================================
--- prof-2.6.7.orig/kernel/profile.c	2004-06-22 10:06:59.034645320 -0700
+++ prof-2.6.7/kernel/profile.c	2004-06-22 10:08:31.884529992 -0700
@@ -8,10 +8,11 @@
 #include <linux/bootmem.h>
 #include <linux/notifier.h>
 #include <linux/mm.h>
+#include <linux/pagemap.h>
 #include <asm/sections.h>
 
 static atomic_t *prof_buffer;
-static unsigned long prof_len, prof_shift;
+static unsigned long prof_len, prof_shift, prof_pages;
 static int prof_on;
 
 int __init profile_setup(char * str)
@@ -33,7 +34,8 @@
  
 	/* only text is profiled */
 	prof_len = ((unsigned long)(_etext - _stext) >> prof_shift) + 1;
-	prof_buffer = alloc_bootmem(sizeof(atomic_t)*prof_len);
+	prof_buffer = alloc_bootmem_pages(sizeof(atomic_t)*prof_len);
+	prof_pages = PAGE_ALIGN(prof_len*sizeof(atomic_t))/PAGE_SIZE;
 	atomic_set(prof_buffer, 1 << prof_shift);
 }
 
@@ -167,6 +169,7 @@
 EXPORT_SYMBOL_GPL(profile_event_unregister);
 
 #ifdef CONFIG_PROC_FS
+#include <linux/proc_fs.h>
 /*
  * This function accesses profiling information. The returned data is
  * binary: the sampling step and the actual contents of the profile
@@ -180,7 +183,7 @@
 
 	if (p >= sizeof(atomic_t)*prof_len)
 		return 0;
-	count = min(prof_len*sizeof(atomic_t) - p, count);
+	count = min_t(size_t, prof_len*sizeof(atomic_t) - p, count);
 	if (copy_to_user(buf, (char *)prof_buffer + p, count))
 		return -EFAULT;
 	*ppos += count;
@@ -214,9 +217,40 @@
 	return count;
 }
 
+static int mmap_profile(struct file *file, struct vm_area_struct *vma)
+{
+	unsigned long pfn, vaddr, base_pfn = __pa(prof_buffer)/PAGE_SIZE;
+	if (vma->vm_pgoff + vma_pages(vma) > prof_pages)
+		return -ENODEV;
+	vma->vm_flags |= VM_RESERVED|VM_IO;
+	for (vaddr = vma->vm_start; vaddr < vma->vm_end; vaddr += PAGE_SIZE) {
+		pgd_t *pgd = pgd_offset(vma->vm_mm, vaddr);
+		pmd_t *pmd;
+		pte_t *pte, pte_val;
+		spin_lock(&vma->vm_mm->page_table_lock);
+		pmd = pmd_alloc(vma->vm_mm, pgd, vaddr);
+		if (!pmd)
+			goto enomem;
+		pte = pte_alloc_map(vma->vm_mm, pmd, vaddr);
+		if (!pte)
+			goto enomem;
+		pfn = base_pfn + linear_page_index(vma, vaddr);
+		pte_val = pfn_pte(pfn, vma->vm_page_prot);
+		set_pte(pte, pte_val);
+		update_mmu_cache(vma, vaddr, pte_val);
+		pte_unmap(pte);
+		spin_unlock(&vma->vm_mm->page_table_lock);
+	}
+	return 0;
+enomem:
+	spin_unlock(&vma->vm_mm->page_table_lock);
+	return -ENOMEM;
+}
+
 static struct file_operations proc_profile_operations = {
 	.read		= read_profile,
 	.write		= write_profile,
+	.mmap		= mmap_profile,
 };
 
 void create_proc_profile(void)

  reply	other threads:[~2004-06-22 17:18 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-22 15:16 [profile]: [0/23] mmap() support for /proc/profile William Lee Irwin III
2004-06-22 15:16 ` [profile]: [1/23] move proc_profile_operations to profile.c William Lee Irwin III
2004-06-22 15:16   ` [profile]: [2/23] ppc32 profiling cleanups William Lee Irwin III
2004-06-22 15:16     ` [profile]: [3/23] mips " William Lee Irwin III
2004-06-22 15:16       ` [profile]: [4/23] sparc64 " William Lee Irwin III
2004-06-22 15:16         ` [profile]: [5/23] m68knommu " William Lee Irwin III
2004-06-22 15:16           ` [profile]: [6/23] sparc32 " William Lee Irwin III
2004-06-22 15:16             ` [profile]: [7/23] superh " William Lee Irwin III
2004-06-22 15:17               ` [profile]: [8/23] arm26 " William Lee Irwin III
2004-06-22 15:17                 ` [profile]: [9/23] m68k " William Lee Irwin III
2004-06-22 15:17                   ` [profile]: [10/23] ia64 " William Lee Irwin III
2004-06-22 15:17                     ` [profile]: [11/23] alpha " William Lee Irwin III
2004-06-22 15:17                       ` [profile]: [12/23] ppc64 " William Lee Irwin III
2004-06-22 15:17                         ` [profile]: [13/23] arm " William Lee Irwin III
2004-06-22 15:17                           ` [profile]: [14/23] parisc " William Lee Irwin III
2004-06-22 15:17                             ` [profile]: [15/23] h8300 " William Lee Irwin III
2004-06-22 15:17                               ` [profile]: [16/23] s390 " William Lee Irwin III
2004-06-22 15:17                                 ` [profile]: [17/23] x86-64 " William Lee Irwin III
2004-06-22 15:17                                   ` [profile]: [18/23] i386 " William Lee Irwin III
2004-06-22 15:17                                     ` [profile]: [19/23] remove public decls of profile.c internal state William Lee Irwin III
2004-06-22 15:17                                       ` [profile]: [20/23] clean up profile_init() not to oversize buffer William Lee Irwin III
2004-06-22 15:17                                         ` [profile]: [21/23] use atomic_t for prof_buffer William Lee Irwin III
2004-06-22 15:18                                           ` [profile]: [22/23] put 1 << prof_shift at prof_buffer[0] William Lee Irwin III
2004-06-22 15:18                                             ` [profile]: [23/23] add mmap() support for /proc/profile William Lee Irwin III
2004-06-22 17:03                                               ` William Lee Irwin III
2004-06-22 17:10                                             ` [profile]: [22/23] put 1 << prof_shift at prof_buffer[0] William Lee Irwin III
2004-06-22 17:12                                               ` William Lee Irwin III [this message]
2004-06-22 20:01                                           ` [profile]: [21/23] use atomic_t for prof_buffer David S. Miller
2004-06-22 20:16                                             ` William Lee Irwin III
2004-06-22 20:47                                               ` David S. Miller
2004-06-29 18:56                     ` [profile]: [10/23] ia64 profiling cleanups David Mosberger
2004-06-29 19:23                       ` William Lee Irwin III
2004-06-22 23:16 ` [profile]: [0/23] mmap() support for /proc/profile Anton Blanchard
2004-06-23  1:58   ` David S. Miller
2004-06-23  2:05   ` William Lee Irwin III
2004-06-23  3:00     ` Anton Blanchard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040622171207.GE2135@holomorphy.com \
    --to=wli@holomorphy.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rddunlap@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.