From e13168648d5947955e0fd4fbf396f891ae53921f Mon Sep 17 00:00:00 2001 From: Vladimir Chtchetkine Date: Thu, 26 Aug 2010 09:03:54 -0700 Subject: Moved nand and netspeed initialization from main to core. Change-Id: Ide3914fa52f62f618d39ac20f02bce8185a6805a --- hw/goldfish_nand.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 2 deletions(-) (limited to 'hw/goldfish_nand.c') diff --git a/hw/goldfish_nand.c b/hw/goldfish_nand.c index 2d23baa..1570095 100644 --- a/hw/goldfish_nand.c +++ b/hw/goldfish_nand.c @@ -76,13 +76,13 @@ nand_threshold_update( nand_threshold* t, uint32_t len ) avail = len; if (t->counter == 0) { - T("%s: starting threshold counting to %lld", + T("%s: starting threshold counting to %lld", __FUNCTION__, t->limit); } t->counter += avail; if (t->counter >= t->limit) { /* threshold reach, send a signal to an external process */ - T( "%s: sending signal %d to pid %d !", + T( "%s: sending signal %d to pid %d !", __FUNCTION__, t->signal, t->pid ); kill( t->pid, t->signal ); @@ -632,3 +632,109 @@ bad_arg_and_value: exit(1); } +#ifdef CONFIG_NAND_LIMITS + +static uint64_t +parse_nand_rw_limit( const char* value ) +{ + char* end; + uint64_t val = strtoul( value, &end, 0 ); + + if (end == value) { + derror( "bad parameter value '%s': expecting unsigned integer", value ); + exit(1); + } + + switch (end[0]) { + case 'K': val <<= 10; break; + case 'M': val <<= 20; break; + case 'G': val <<= 30; break; + case 0: break; + default: + derror( "bad read/write limit suffix: use K, M or G" ); + exit(1); + } + return val; +} + +void +parse_nand_limits(char* limits) +{ + int pid = -1, signal = -1; + int64_t reads = 0, writes = 0; + char* item = limits; + + /* parse over comma-separated items */ + while (item && *item) { + char* next = strchr(item, ','); + char* end; + + if (next == NULL) { + next = item + strlen(item); + } else { + *next++ = 0; + } + + if ( !memcmp(item, "pid=", 4) ) { + pid = strtol(item+4, &end, 10); + if (end == NULL || *end) { + derror( "bad parameter, expecting pid=, got '%s'", + item ); + exit(1); + } + if (pid <= 0) { + derror( "bad parameter: process identifier must be > 0" ); + exit(1); + } + } + else if ( !memcmp(item, "signal=", 7) ) { + signal = strtol(item+7,&end, 10); + if (end == NULL || *end) { + derror( "bad parameter: expecting signal=, got '%s'", + item ); + exit(1); + } + if (signal <= 0) { + derror( "bad parameter: signal number must be > 0" ); + exit(1); + } + } + else if ( !memcmp(item, "reads=", 6) ) { + reads = parse_nand_rw_limit(item+6); + } + else if ( !memcmp(item, "writes=", 7) ) { + writes = parse_nand_rw_limit(item+7); + } + else { + derror( "bad parameter '%s' (see -help-nand-limits)", item ); + exit(1); + } + item = next; + } + if (pid < 0) { + derror( "bad paramater: missing pid=" ); + exit(1); + } + else if (signal < 0) { + derror( "bad parameter: missing signal=" ); + exit(1); + } + else if (reads == 0 && writes == 0) { + dwarning( "no read or write limit specified. ignoring -nand-limits" ); + } else { + nand_threshold* t; + + t = &android_nand_read_threshold; + t->pid = pid; + t->signal = signal; + t->counter = 0; + t->limit = reads; + + t = &android_nand_write_threshold; + t->pid = pid; + t->signal = signal; + t->counter = 0; + t->limit = writes; + } +} +#endif /* CONFIG_NAND_LIMITS */ -- cgit v1.1