summaryrefslogtreecommitdiff
path: root/apps/tagcache.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tagcache.c')
-rw-r--r--apps/tagcache.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c
index a53bdc7f84..926ba7b3c7 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -57,6 +57,7 @@
57#include <stdlib.h> 57#include <stdlib.h>
58#include <ctype.h> 58#include <ctype.h>
59#include "config.h" 59#include "config.h"
60#include "ata_idle_notify.h"
60#include "thread.h" 61#include "thread.h"
61#include "kernel.h" 62#include "kernel.h"
62#include "system.h" 63#include "system.h"
@@ -154,9 +155,6 @@ static struct tagcache_command_entry command_queue[TAGCACHE_COMMAND_QUEUE_LENGTH
154static volatile int command_queue_widx = 0; 155static volatile int command_queue_widx = 0;
155static volatile int command_queue_ridx = 0; 156static volatile int command_queue_ridx = 0;
156static struct mutex command_queue_mutex; 157static struct mutex command_queue_mutex;
157/* Timestamp of the last added event, so we can wait a bit before committing the
158 * whole queue at once. */
159static long command_queue_timestamp = 0;
160 158
161/* Tag database structures. */ 159/* Tag database structures. */
162 160
@@ -3030,26 +3028,16 @@ static bool command_queue_is_full(void)
3030 3028
3031 return (next == command_queue_ridx); 3029 return (next == command_queue_ridx);
3032} 3030}
3033 3031bool command_queue_sync_callback(void)
3034void run_command_queue(bool force)
3035{ 3032{
3033
3036 struct master_header myhdr; 3034 struct master_header myhdr;
3037 int masterfd; 3035 int masterfd;
3038
3039 if (COMMAND_QUEUE_IS_EMPTY)
3040 return;
3041
3042 if (!force && !command_queue_is_full()
3043 && current_tick - TAGCACHE_COMMAND_QUEUE_COMMIT_DELAY
3044 < command_queue_timestamp)
3045 {
3046 return;
3047 }
3048 3036
3049 mutex_lock(&command_queue_mutex); 3037 mutex_lock(&command_queue_mutex);
3050 3038
3051 if ( (masterfd = open_master_fd(&myhdr, true)) < 0) 3039 if ( (masterfd = open_master_fd(&myhdr, true)) < 0)
3052 return; 3040 return false;
3053 3041
3054 while (command_queue_ridx != command_queue_widx) 3042 while (command_queue_ridx != command_queue_widx)
3055 { 3043 {
@@ -3064,7 +3052,7 @@ void run_command_queue(bool force)
3064 3052
3065 /* Re-open the masterfd. */ 3053 /* Re-open the masterfd. */
3066 if ( (masterfd = open_master_fd(&myhdr, true)) < 0) 3054 if ( (masterfd = open_master_fd(&myhdr, true)) < 0)
3067 return; 3055 return true;
3068 3056
3069 break; 3057 break;
3070 } 3058 }
@@ -3081,7 +3069,20 @@ void run_command_queue(bool force)
3081 3069
3082 close(masterfd); 3070 close(masterfd);
3083 3071
3072 tc_stat.queue_length = 0;
3084 mutex_unlock(&command_queue_mutex); 3073 mutex_unlock(&command_queue_mutex);
3074 return true;
3075}
3076
3077void run_command_queue(bool force)
3078{
3079 if (COMMAND_QUEUE_IS_EMPTY)
3080 return;
3081
3082 if (force || command_queue_is_full())
3083 command_queue_sync_callback();
3084 else
3085 register_ata_idle_func(command_queue_sync_callback);
3085} 3086}
3086 3087
3087static void queue_command(int cmd, long idx_id, int tag, long data) 3088static void queue_command(int cmd, long idx_id, int tag, long data)
@@ -3106,7 +3107,9 @@ static void queue_command(int cmd, long idx_id, int tag, long data)
3106 ce->data = data; 3107 ce->data = data;
3107 3108
3108 command_queue_widx = next; 3109 command_queue_widx = next;
3109 command_queue_timestamp = current_tick; 3110
3111 tc_stat.queue_length++;
3112
3110 mutex_unlock(&command_queue_mutex); 3113 mutex_unlock(&command_queue_mutex);
3111 break; 3114 break;
3112 } 3115 }