public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Bryan Wu <bryan.wu@analog.com>
To: torvalds@linux-foundation.org, akpm@linux-foundation.org,
	linux-kernel@vger.kernel.org
Cc: Mike Frysinger <michael.frysinger@analog.com>,
	Bryan Wu <bryan.wu@analog.com>
Subject: [PATCH 07/20] Blackfin arch: implement a basic /proc/sram file for L1 allocation visibility
Date: Mon, 28 May 2007 16:37:42 +0800	[thread overview]
Message-ID: <11803414782093-git-send-email-bryan.wu@analog.com> (raw)
In-Reply-To: <11803414753217-git-send-email-bryan.wu@analog.com>

From: Mike Frysinger <michael.frysinger@analog.com>

implement a basic /proc/sram file for L1 allocation visibility until we can
rewrite the entire L1 allocator (which would include a proper mechanism)

Signed-off-by: Mike Frysinger <michael.frysinger@analog.com>
Signed-off-by: Bryan Wu <bryan.wu@analog.com>
---
 arch/blackfin/mm/blackfin_sram.c |   87 ++++++++++++++++++++++++++++++++------
 1 files changed, 74 insertions(+), 13 deletions(-)

diff --git a/arch/blackfin/mm/blackfin_sram.c b/arch/blackfin/mm/blackfin_sram.c
index 0241764..38d9478 100644
--- a/arch/blackfin/mm/blackfin_sram.c
+++ b/arch/blackfin/mm/blackfin_sram.c
@@ -63,6 +63,7 @@ struct l1_sram_piece {
 	void *paddr;
 	int size;
 	int flag;
+	pid_t pid;
 };
 
 static struct l1_sram_piece l1_ssram[CONFIG_L1_MAX_PIECE];
@@ -97,23 +98,22 @@ void __init l1sram_init(void)
 void __init l1_data_sram_init(void)
 {
 #if L1_DATA_A_LENGTH != 0
-	printk(KERN_INFO "Blackfin DATA_A SRAM: %d KB\n",
-	       L1_DATA_A_LENGTH >> 10);
-
 	memset(&l1_data_A_sram, 0x00, sizeof(l1_data_A_sram));
-	l1_data_A_sram[0].paddr = (void*)L1_DATA_A_START +
-		(_ebss_l1 - _sdata_l1);
+	l1_data_A_sram[0].paddr = (void*)L1_DATA_A_START + (_ebss_l1 - _sdata_l1);
 	l1_data_A_sram[0].size = L1_DATA_A_LENGTH - (_ebss_l1 - _sdata_l1);
 	l1_data_A_sram[0].flag = SRAM_SLT_FREE;
+
+	printk(KERN_INFO "Blackfin Data A SRAM: %d KB (%d KB free)\n",
+	       L1_DATA_A_LENGTH >> 10, l1_data_A_sram[0].size >> 10);
 #endif
 #if L1_DATA_B_LENGTH != 0
-	printk(KERN_INFO "Blackfin DATA_B SRAM: %d KB\n",
-	       L1_DATA_B_LENGTH >> 10);
-
 	memset(&l1_data_B_sram, 0x00, sizeof(l1_data_B_sram));
 	l1_data_B_sram[0].paddr = (void*)L1_DATA_B_START;
 	l1_data_B_sram[0].size = L1_DATA_B_LENGTH;
 	l1_data_B_sram[0].flag = SRAM_SLT_FREE;
+
+	printk(KERN_INFO "Blackfin Data B SRAM: %d KB (%d KB free)\n",
+	       L1_DATA_B_LENGTH >> 10, l1_data_B_sram[0].size >> 10);
 #endif
 
 	/* mutex initialize */
@@ -123,13 +123,13 @@ void __init l1_data_sram_init(void)
 void __init l1_inst_sram_init(void)
 {
 #if L1_CODE_LENGTH != 0
-	printk(KERN_INFO "Blackfin Instruction SRAM: %d KB\n",
-	       L1_CODE_LENGTH >> 10);
-
 	memset(&l1_inst_sram, 0x00, sizeof(l1_inst_sram));
 	l1_inst_sram[0].paddr = (void*)L1_CODE_START + (_etext_l1 - _stext_l1);
 	l1_inst_sram[0].size = L1_CODE_LENGTH - (_etext_l1 - _stext_l1);
 	l1_inst_sram[0].flag = SRAM_SLT_FREE;
+
+	printk(KERN_INFO "Blackfin Instruction SRAM: %d KB (%d KB free)\n",
+	       L1_CODE_LENGTH >> 10, l1_inst_sram[0].size >> 10);
 #endif
 
 	/* mutex initialize */
@@ -155,6 +155,7 @@ static void *_l1_sram_alloc(size_t size, struct l1_sram_piece *pfree, int count)
 		    && (pfree[i].size >= size)) {
 			addr = pfree[i].paddr;
 			pfree[i].flag = SRAM_SLT_ALLOCATED;
+			pfree[i].pid = current->pid;
 			index = i;
 			break;
 		}
@@ -166,6 +167,7 @@ static void *_l1_sram_alloc(size_t size, struct l1_sram_piece *pfree, int count)
 	if (pfree[i].size > size) {
 		for (i = 0; i < count; i++) {
 			if (pfree[i].flag == SRAM_SLT_NULL) {
+				pfree[i].pid = 0;
 				pfree[i].flag = SRAM_SLT_FREE;
 				pfree[i].paddr = addr + size;
 				pfree[i].size = pfree[index].size - size;
@@ -198,13 +200,13 @@ static void *_l1_sram_alloc_max(struct l1_sram_piece *pfree, int count,
 		return NULL;
 	*psize = best;
 
+	pfree[index].pid = current->pid;
 	pfree[index].flag = SRAM_SLT_ALLOCATED;
 	return addr;
 }
 
 /* L1 memory free function */
-static int _l1_sram_free(const void *addr,
-			 struct l1_sram_piece *pfree, int count)
+static int _l1_sram_free(const void *addr, struct l1_sram_piece *pfree, int count)
 {
 	int i, index = 0;
 
@@ -222,12 +224,14 @@ static int _l1_sram_free(const void *addr,
 	if (i >= count)
 		return -1;
 
+	pfree[index].pid = 0;
 	pfree[index].flag = SRAM_SLT_FREE;
 
 	/* link the next address slot */
 	for (i = 0; i < count; i++) {
 		if (((pfree[index].paddr + pfree[index].size) == pfree[i].paddr)
 		    && (pfree[i].flag == SRAM_SLT_FREE)) {
+			pfree[i].pid = 0;
 			pfree[i].flag = SRAM_SLT_NULL;
 			pfree[index].size += pfree[i].size;
 			pfree[index].flag = SRAM_SLT_FREE;
@@ -538,3 +542,60 @@ void *sram_alloc_with_lsl(size_t size, unsigned long flags)
 	return addr;
 }
 EXPORT_SYMBOL(sram_alloc_with_lsl);
+
+#ifdef CONFIG_PROC_FS
+/* Once we get a real allocator, we'll throw all of this away.
+ * Until then, we need some sort of visibility into the L1 alloc.
+ */
+static void _l1sram_proc_read(char *buf, int *len, const char *desc,
+                              struct l1_sram_piece *pfree, const int array_size)
+{
+	int i;
+
+	*len += sprintf(&buf[*len], "--- L1 %-14s Size  PID State\n", desc);
+	for (i = 0; i < array_size; ++i) {
+		const char *alloc_type;
+		switch (pfree[i].flag) {
+			case SRAM_SLT_NULL:      alloc_type = "NULL"; break;
+			case SRAM_SLT_FREE:      alloc_type = "FREE"; break;
+			case SRAM_SLT_ALLOCATED: alloc_type = "ALLOCATED"; break;
+			default:                 alloc_type = "????"; break;
+		}
+		*len += sprintf(&buf[*len], "%p-%p %8i %4i %s\n",
+			pfree[i].paddr, pfree[i].paddr + pfree[i].size,
+			pfree[i].size, pfree[i].pid, alloc_type);
+	}
+}
+static int l1sram_proc_read(char *buf, char **start, off_t offset, int count,
+                            int *eof, void *data)
+{
+	int len = 0;
+
+	_l1sram_proc_read(buf, &len, "Scratchpad", l1_ssram, ARRAY_SIZE(l1_ssram));
+#if L1_DATA_A_LENGTH != 0
+	_l1sram_proc_read(buf, &len, "Data A", l1_data_A_sram, ARRAY_SIZE(l1_data_A_sram));
+#endif
+#if L1_DATA_B_LENGTH != 0
+	_l1sram_proc_read(buf, &len, "Data B", l1_data_B_sram, ARRAY_SIZE(l1_data_B_sram));
+#endif
+#if L1_CODE_LENGTH != 0
+	_l1sram_proc_read(buf, &len, "Instruction", l1_inst_sram, ARRAY_SIZE(l1_inst_sram));
+#endif
+
+	return len;
+}
+
+static int __init l1sram_proc_init(void)
+{
+	struct proc_dir_entry *ptr;
+	ptr = create_proc_entry("sram", S_IFREG | S_IRUGO, NULL);
+	if (!ptr) {
+		printk(KERN_WARNING "unable to create /proc/sram\n");
+		return -1;
+	}
+	ptr->owner = THIS_MODULE;
+	ptr->read_proc = l1sram_proc_read;
+	return 0;
+}
+late_initcall(l1sram_proc_init);
+#endif
-- 
1.5.2

  parent reply	other threads:[~2007-05-28  8:39 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-28  8:37 [PATCH 00/20] Blackfin update for 2.6.22-rc3 Bryan Wu
2007-05-28  8:37 ` [PATCH 01/20] Blackfin arch: remove defconfig file Bryan Wu
2007-05-28  8:37 ` [PATCH 02/20] Blackfin arch: DMA code minor naming convention fix Bryan Wu
2007-05-28  8:37 ` [PATCH 03/20] Blackfin arch: spelling fixes Bryan Wu
2007-05-28  8:37 ` [PATCH 04/20] Blackfin arch: fix bug ad1836 fails to build properly for BF533-EZKIT Bryan Wu
2007-05-28  8:37 ` [PATCH 05/20] Blackfin arch: all symbols were offset by 4k, since we didn't have the __text label Bryan Wu
2007-05-28  8:37 ` [PATCH 06/20] Blackfin arch: mark our memory init functions with __init so they get freed after init Bryan Wu
2007-05-28  8:37 ` Bryan Wu [this message]
2007-05-28  8:37 ` [PATCH 08/20] Blackfin arch: Add header files for BF548 Bryan Wu
2007-05-28  8:37 ` [PATCH 09/20] Blackfin arch: fixup Blackfin MAINTIANERS team member list Bryan Wu
2007-05-28 11:48   ` Pekka Enberg
2007-05-28 14:33     ` Robin Getz
2007-05-28  8:37 ` [PATCH 10/20] Blackfin arch: scrub old console defines Bryan Wu
2007-05-28  8:37 ` [PATCH 11/20] Blackfin arch: update defconfigs Bryan Wu
2007-05-28  8:37 ` [PATCH 12/20] Blackfin arch: unify differences between our diff head.S files -- no functional changes Bryan Wu
2007-05-28  8:37 ` [PATCH 13/20] Blackfin arch: move more of our startup code to .init so it can be freed once we are up and running Bryan Wu
2007-05-28  8:37 ` [PATCH 14/20] Blackfin arch: add proper ENDPROC() Bryan Wu
2007-05-28  8:37 ` [PATCH 15/20] Blackfin serial driver: hook up our UARTs STP bit with userspaces CMSPAR Bryan Wu
2007-05-28  8:37 ` [PATCH 16/20] Blackfin serial driver: ignore framing and parity errors Bryan Wu
2007-05-28  8:37 ` [PATCH 17/20] Blackfin RTC drivers: update MAINTAINERS information Bryan Wu
2007-05-28  8:37 ` [PATCH 18/20] Blackfin SPI driver: tweak spi cleanup function to match newer kernel changes Bryan Wu
2007-05-28  8:37 ` [PATCH 19/20] Blackfin on-chip watchdog driver Bryan Wu
2007-05-29 17:20   ` Mike Frysinger
2007-05-31 20:17     ` Mike Frysinger
2007-05-28  8:37 ` [PATCH 20/20] binfmt_flat: minimum support for the Blackfin relocations Bryan Wu
2007-05-29 20:59 ` [PATCH 00/20] Blackfin update for 2.6.22-rc3 Linus Torvalds
2007-05-29 23:31   ` Bernd Schmidt
2007-05-30  1:04     ` Linus Torvalds
2007-05-30  2:31   ` Bryan Wu
2007-05-30  2:42     ` Andrew Morton
2007-05-30  2:56       ` Bryan Wu
2007-05-30 13:09   ` Robin Getz
2007-05-30 13:30     ` Sam Ravnborg
2007-05-30 13:48       ` Robin Getz
2007-05-30 15:53     ` Linus Torvalds

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=11803414782093-git-send-email-bryan.wu@analog.com \
    --to=bryan.wu@analog.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.frysinger@analog.com \
    --cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox