From 82f9056988331572e01231d70fadc64b7ab76c6f Mon Sep 17 00:00:00 2001 From: Daniel Ankers Date: Sun, 4 Mar 2007 20:06:41 +0000 Subject: Dual core support for PP502x players (iPod G4 and later, iriver h10, Sansa - iPod G3 will be coming soon.) This allows threads to be run on either core provided that all communications between the cores is done using uncached memory. There should be no significant change in battery life from doing this. Documentation (on the RockboxKernel wiki page) will follow shortly. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12601 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs.c | 2 +- apps/codecs.h | 5 +++-- apps/main.c | 14 ++++++++++---- apps/playback.c | 24 +++++++++++++----------- apps/playlist.c | 3 ++- apps/plugin.c | 1 - apps/plugin.h | 8 ++------ apps/plugins/alpine_cdc.c | 3 ++- apps/plugins/battery_bench.c | 3 ++- apps/plugins/mpegplayer/mpegplayer.c | 10 ++++------ apps/tagcache.c | 3 ++- 11 files changed, 41 insertions(+), 35 deletions(-) (limited to 'apps') diff --git a/apps/codecs.c b/apps/codecs.c index 0c6ddd0422..ccfa449d51 100644 --- a/apps/codecs.c +++ b/apps/codecs.c @@ -123,7 +123,7 @@ struct codec_api ci = { ¤t_tick, default_event_handler, default_event_handler_ex, - create_thread_on_core, + create_thread, remove_thread, reset_poweroff_timer, #ifndef SIMULATOR diff --git a/apps/codecs.h b/apps/codecs.h index 6710afdc8e..3c2b754dac 100644 --- a/apps/codecs.h +++ b/apps/codecs.h @@ -199,9 +199,10 @@ struct codec_api { long* current_tick; long (*default_event_handler)(long event); long (*default_event_handler_ex)(long event, void (*callback)(void *), void *parameter); - struct thread_entry* (*create_thread)(unsigned int core, void (*function)(void), + struct thread_entry* (*create_thread)(void (*function)(void), void* stack, int stack_size, const char *name - IF_PRIO(, int priority)); + IF_PRIO(, int priority) + IF_COP(, unsigned int core, bool fallback)); void (*remove_thread)(struct thread_entry *thread); void (*reset_poweroff_timer)(void); #ifndef SIMULATOR diff --git a/apps/main.c b/apps/main.c index 6286b68ed1..e4d90bce61 100644 --- a/apps/main.c +++ b/apps/main.c @@ -296,6 +296,9 @@ static void init(void) #if CONFIG_CHARGING && (CONFIG_CPU == SH7034) /* if nobody initialized ATA before, I consider this a cold start */ bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */ +#endif +#ifdef CPU_PP + COP_CTL = PROC_WAKE; #endif system_init(); kernel_init(); @@ -549,19 +552,22 @@ void cop_main(void) so it should not be assumed that the coprocessor be usable even on platforms which support it. - At present the COP sleeps unless it receives a message from the CPU telling - it that we are loading a new kernel, so must reboot */ + A kernel thread runs on the coprocessor which waits for other threads to be + added, and gracefully handles RoLo */ #if CONFIG_CPU == PP5002 -/* 3G doesn't have Rolo support yet */ +/* 3G doesn't have Rolo or dual core support yet */ while(1) { COP_CTL = PROC_SLEEP; } #else extern volatile unsigned char cpu_message; + system_init(); + kernel_init(); + while(cpu_message != COP_REBOOT) { - COP_CTL = PROC_SLEEP; + sleep(HZ); } rolo_restart_cop(); #endif /* PP5002 */ diff --git a/apps/playback.c b/apps/playback.c index fe7a9f6ab1..89caec92aa 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -194,9 +194,9 @@ static bool audio_is_initialized = false; /* TBD: Split out "audio" and "playback" (ie. calling) threads */ /* Main state control */ -static volatile bool audio_codec_loaded; /* Is codec loaded? (C/A-) */ -static volatile bool playing; /* Is audio playing? (A) */ -static volatile bool paused; /* Is audio paused? (A/C-) */ +static volatile bool audio_codec_loaded NOCACHEBSS_ATTR;/* Codec loaded? (C/A-) */ +static volatile bool playing NOCACHEBSS_ATTR; /* Is audio playing? (A) */ +static volatile bool paused NOCACHEBSS_ATTR; /* Is audio paused? (A/C-) */ static volatile bool filling IDATA_ATTR; /* Is file buffer refilling? (A/C-) */ /* Ring buffer where compressed audio and codecs are loaded */ @@ -290,7 +290,7 @@ static void audio_reset_buffer(size_t pcmbufsize); /* Codec thread */ extern struct codec_api ci; -static struct event_queue codec_queue; +static struct event_queue codec_queue NOCACHEBSS_ATTR; static long codec_stack[(DEFAULT_STACK_SIZE + 0x2000)/sizeof(long)] IBSS_ATTR; static const char codec_thread_name[] = "codec"; @@ -304,7 +304,7 @@ static volatile int current_codec IDATA_ATTR; /* Current codec (normal/voice) */ extern struct codec_api ci_voice; static struct thread_entry *voice_thread_p = NULL; -static struct event_queue voice_queue; +static struct event_queue voice_queue NOCACHEBSS_ATTR; static long voice_stack[(DEFAULT_STACK_SIZE + 0x2000)/sizeof(long)] IBSS_ATTR_VOICE_STACK; static const char voice_thread_name[] = "voice codec"; @@ -324,12 +324,12 @@ static unsigned char *iram_buf[2] = { NULL, NULL }; /* Pointer to DRAM buffers for normal/voice codecs */ static unsigned char *dram_buf[2] = { NULL, NULL }; /* Mutex to control which codec (normal/voice) is running */ -static struct mutex mutex_codecthread; +static struct mutex mutex_codecthread NOCACHEBSS_ATTR; /* Voice state */ static volatile bool voice_thread_start; /* Triggers voice playback (A/V) */ -static volatile bool voice_is_playing; /* Is voice currently playing? (V) */ -static volatile bool voice_codec_loaded; /* Is voice codec loaded (V/A-) */ +static volatile bool voice_is_playing NOCACHEBSS_ATTR; /* Is voice currently playing? (V) */ +static volatile bool voice_codec_loaded NOCACHEBSS_ATTR; /* Is voice codec loaded (V/A-) */ static char *voicebuf; static size_t voice_remaining; @@ -863,7 +863,8 @@ void audio_preinit(void) queue_init(&codec_queue, true); create_thread(audio_thread, audio_stack, sizeof(audio_stack), - audio_thread_name IF_PRIO(, PRIORITY_BUFFERING)); + audio_thread_name IF_PRIO(, PRIORITY_BUFFERING) + IF_COP(, CPU, false)); } void audio_init(void) @@ -888,7 +889,7 @@ void voice_init(void) queue_init(&voice_queue, true); voice_thread_p = create_thread(voice_thread, voice_stack, sizeof(voice_stack), voice_thread_name - IF_PRIO(, PRIORITY_PLAYBACK)); + IF_PRIO(, PRIORITY_PLAYBACK) IF_COP(, CPU, false)); while (!voice_codec_loaded) yield(); @@ -3533,7 +3534,8 @@ static void audio_playback_init(void) codec_thread_p = create_thread( codec_thread, codec_stack, sizeof(codec_stack), - codec_thread_name IF_PRIO(, PRIORITY_PLAYBACK)); + codec_thread_name IF_PRIO(, PRIORITY_PLAYBACK) + IF_COP(, COP, true)); while (1) { diff --git a/apps/playlist.c b/apps/playlist.c index 6997b12675..0358b6adc4 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -1873,7 +1873,8 @@ void playlist_init(void) memset(playlist->filenames, 0, playlist->max_playlist_size * sizeof(int)); create_thread(playlist_thread, playlist_stack, sizeof(playlist_stack), - playlist_thread_name IF_PRIO(, PRIORITY_BACKGROUND)); + playlist_thread_name IF_PRIO(, PRIORITY_BACKGROUND) + IF_COP(, CPU, false)); queue_init(&playlist_queue, true); #endif } diff --git a/apps/plugin.c b/apps/plugin.c index 5bbff96b04..230b62b819 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -481,7 +481,6 @@ static const struct plugin_api rockbox_api = { sound_default, pcm_record_more, #endif - create_thread_on_core, #ifdef IRIVER_H100_SERIES /* Routines for the iriver_flash -plugin. */ diff --git a/apps/plugin.h b/apps/plugin.h index 48e9c40196..1d161783a1 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -327,7 +327,8 @@ struct plugin_api { long (*default_event_handler_ex)(long event, void (*callback)(void *), void *parameter); struct thread_entry* (*create_thread)(void (*function)(void), void* stack, int stack_size, const char *name - IF_PRIO(, int priority)); + IF_PRIO(, int priority) + IF_COP(, unsigned int core, bool fallback)); void (*remove_thread)(struct thread_entry *thread); void (*reset_poweroff_timer)(void); #ifndef SIMULATOR @@ -595,11 +596,6 @@ struct plugin_api { void (*pcm_record_more)(void *start, size_t size); #endif - struct thread_entry*(*create_thread_on_core)( - unsigned int core, void (*function)(void), - void* stack, int stack_size, - const char *name IF_PRIO(, int priority)); - #ifdef IRIVER_H100_SERIES /* Routines for the iriver_flash -plugin. */ bool (*detect_original_firmware)(void); diff --git a/apps/plugins/alpine_cdc.c b/apps/plugins/alpine_cdc.c index 9c1bc8bd0b..9cc1f9cde4 100644 --- a/apps/plugins/alpine_cdc.c +++ b/apps/plugins/alpine_cdc.c @@ -1171,7 +1171,8 @@ int main(void* parameter) rb->memset(&gTread, 0, sizeof(gTread)); gTread.foreground = true; rb->create_thread(thread, stack, stacksize, "CDC" - IF_PRIO(, PRIORITY_BACKGROUND)); + IF_PRIO(, PRIORITY_BACKGROUND) + IF_COP(, CPU, false)); #ifdef DEBUG do diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c index fff3c2fa57..6e3178237f 100644 --- a/apps/plugins/battery_bench.c +++ b/apps/plugins/battery_bench.c @@ -479,7 +479,8 @@ int main(void) rb->queue_init(&thread_q, true); /* put the thread's queue in the bcast list */ if(rb->create_thread(thread, thread_stack, sizeof(thread_stack), "Battery Benchmark" - IF_PRIO(, PRIORITY_BACKGROUND)) == NULL) + IF_PRIO(, PRIORITY_BACKGROUND) + IF_COP(, CPU, false)) == NULL) { rb->splash(HZ,true,"Cannot create thread!"); return PLUGIN_ERROR; diff --git a/apps/plugins/mpegplayer/mpegplayer.c b/apps/plugins/mpegplayer/mpegplayer.c index 36f54dc224..684a491872 100644 --- a/apps/plugins/mpegplayer/mpegplayer.c +++ b/apps/plugins/mpegplayer/mpegplayer.c @@ -909,19 +909,17 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) videostatus = STREAM_PLAYING; /* We put the video thread on the second processor for multi-core targets. */ -#if NUM_CORES > 1 - if ((videothread_id = rb->create_thread_on_core(COP,decode_mpeg2, -#else if ((videothread_id = rb->create_thread(decode_mpeg2, -#endif - (uint8_t*)video_stack,VIDEO_STACKSIZE,"mpgvideo" IF_PRIO(,PRIORITY_PLAYBACK))) == NULL) + (uint8_t*)video_stack,VIDEO_STACKSIZE,"mpgvideo" IF_PRIO(,PRIORITY_PLAYBACK) + IF_COP(, COP, true))) == NULL) { rb->splash(HZ,true,"Cannot create video thread!"); return PLUGIN_ERROR; } if ((audiothread_id = rb->create_thread(mad_decode, - (uint8_t*)audio_stack,AUDIO_STACKSIZE,"mpgaudio" IF_PRIO(,PRIORITY_PLAYBACK))) == NULL) + (uint8_t*)audio_stack,AUDIO_STACKSIZE,"mpgaudio" IF_PRIO(,PRIORITY_PLAYBACK) + IF_COP(, CPU, false))) == NULL) { rb->splash(HZ,true,"Cannot create audio thread!"); rb->remove_thread(videothread_id); diff --git a/apps/tagcache.c b/apps/tagcache.c index a6a0168353..6b891f1011 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -3941,7 +3941,8 @@ void tagcache_init(void) queue_init(&tagcache_queue, true); create_thread(tagcache_thread, tagcache_stack, sizeof(tagcache_stack), tagcache_thread_name - IF_PRIO(, PRIORITY_BACKGROUND)); + IF_PRIO(, PRIORITY_BACKGROUND) + IF_COP(, CPU, false)); #else tc_stat.initialized = true; allocate_tempbuf(); -- cgit v1.2.3