Bug 559136 - add flags to control stop of context when using memory service
Summary: add flags to control stop of context when using memory service
Status: RESOLVED FIXED
Alias: None
Product: TCF
Classification: Tools
Component: Agent (show other bugs)
Version: 1.6   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 1.7   Edit
Assignee: Project Inbox CLA
QA Contact: Eugene Tarassov CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-13 21:14 EST by Jian Xu CLA
Modified: 2021-06-25 16:23 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jian Xu CLA 2020-01-13 21:14:43 EST
When we call memory service "Memory get" , it will stop other contexts firstly, this can make sure the operation of memory read is atomic. But if memory service is called frequently, it will disturb the normal operation of other contexts and the performance is low. So we hope that there is a way to control stop or not stop. This provides the flexibility. 

--- a/agent/tcf/framework/context.h
+++ b/agent/tcf/framework/context.h
@@ -418,6 +418,7 @@ typedef struct MemoryAccessMode {
     int bypass_addr_check;
     int bypass_cache_sync;
     int verify;
+    int not_need_stop;
 } MemoryAccessMode;

--- a/agent/tcf/services/memoryservice.c
+++ b/agent/tcf/services/memoryservice.c
@@ -356,6 +356,7 @@ static MemoryCommandArgs * read_command_args(char * token, Channel * c, int cmd)
     if (mode & 0x02) buf.mode.verify = 1;
     if (mode & 0x04) buf.mode.bypass_addr_check = 1;
     if (mode & 0x08) buf.mode.bypass_cache_sync = 1;
+    if (mode & 0x10) buf.mode.not_need_stop = 1;
     switch (cmd) {
     case CMD_SET:
         json_read_binary_start(&buf.state, &c->inp);
@@ -514,6 +515,7 @@ static void memory_get_cache_client(void * parm) {
     ContextAddress addr = args->addr;
     unsigned long size = args->size;
     unsigned long pos = 0;
+    unsigned long nostop = args->mode.not_need_stop;
     int err = 0;
     MemoryErrorInfo err_info;
     JsonWriteBinaryState state;
@@ -524,13 +526,16 @@ static void memory_get_cache_client(void * parm) {
     if (ctx == NULL) err = ERR_INV_CONTEXT;
     else if (ctx->exited) err = ERR_ALREADY_EXITED;

-    if (size > 0 && err == 0) {
-        Context * mem = context_get_group(ctx, CONTEXT_GROUP_PROCESS);
-        if ((mem->mem_access & MEM_ACCESS_RD_STOP) != 0) {
-            check_all_stopped(ctx);
-        }
-        if ((mem->mem_access & MEM_ACCESS_RD_RUNNING) == 0) {
-            if (!is_all_stopped(ctx)) err = set_errno(ERR_IS_RUNNING, "Cannot read memory if not stopped");
+    if(nostop != 1)
+    {
+        if (size > 0 && err == 0) {
+            Context * mem = context_get_group(ctx, CONTEXT_GROUP_PROCESS);
+            if ((mem->mem_access & MEM_ACCESS_RD_STOP) != 0) {
+                check_all_stopped(ctx);
+            }
+            if ((mem->mem_access & MEM_ACCESS_RD_RUNNING) == 0) {
+                if (!is_all_stopped(ctx)) err = set_errno(ERR_IS_RUNNING, "Cannot read memory if not stopped");
+            }
         }
     }
Comment 1 Jian Xu CLA 2020-01-20 21:12:23 EST
Can you take a look at this ?
Comment 2 Eugene Tarassov CLA 2020-02-05 22:10:33 EST
I have added the flag.
You need to make sure your context implementation sets MEM_ACCESS_RD_RUNNING.
Comment 3 Jian Xu CLA 2020-02-05 22:38:47 EST
I think I can't set MEM_ACCESS_RD_RUNNING for context. If dont_stop flag is zero, check_all_stopped will be called, but is_all_stopped will not be called. Can you modify it this way? It suits my needs better. It's also simpler.

+       if(!args->mode.dont_stop)
+       {
        if ((mem->mem_access & MEM_ACCESS_RD_STOP) != 0) {
            check_all_stopped(ctx);
        }
        if ((mem->mem_access & MEM_ACCESS_RD_RUNNING) == 0) {
            if (!is_all_stopped(ctx)) err = set_errno(ERR_IS_RUNNING, "Cannot read memory if not stopped");
        }
+       }