Merge "gpu-compute: enable kernel-end WB functionality" into agutierr/master-gcn3-staging
diff --git a/configs/example/apu_se.py b/configs/example/apu_se.py
index 453e2c2..0e266a6 100644
--- a/configs/example/apu_se.py
+++ b/configs/example/apu_se.py
@@ -240,13 +240,23 @@
 # So, all GPU protocols other than GPU_RfO should make their writes
 # visible to the global memory and should read from global memory
 # during kernal boundary. The pipeline initiates(or do not initiate)
-# the acquire/release operation depending on this impl_kern_boundary_sync
-# flag. This flag=true means pipeline initiates a acquire/release operation
-# at kernel boundary.
+# the acquire/release operation depending on these impl_kern_launch_rel
+# and impl_kern_end_rel flags.  The flag=true means pipeline initiates
+# a acquire/release operation at kernel launch/end.
+# VIPER protocols (GPU_VIPER, GPU_VIPER_Region and GPU_VIPER_Baseline)
+# are write-through based, and thus only imple_kern_launch_acq needs to
+# set.
 if buildEnv['PROTOCOL'] == 'GPU_RfO':
-    shader.impl_kern_boundary_sync = False
+    shader.impl_kern_launch_acq = False
+    shader.impl_kern_end_rel = False
+elif (buildEnv['PROTOCOL'] != 'GPU_VIPER' or
+        buildEnv['PROTOCOL'] != 'GPU_VIPER_Region' or
+        buildEnv['PROTOCOL'] != 'GPU_VIPER_Baseline'):
+    shader.impl_kern_launch_acq = True
+    shader.impl_kern_end_rel = False
 else:
-    shader.impl_kern_boundary_sync = True
+    shader.impl_kern_launch_acq = True
+    shader.impl_kern_end_rel = True
 
 # Switching off per-lane TLB by default
 per_lane = False
diff --git a/src/arch/x86/linux/process.cc b/src/arch/x86/linux/process.cc
index 5f2bdbb..e39b73b 100644
--- a/src/arch/x86/linux/process.cc
+++ b/src/arch/x86/linux/process.cc
@@ -313,7 +313,7 @@
     /*  83 */ SyscallDesc("mkdir", mkdirFunc),
     /*  84 */ SyscallDesc("rmdir", rmdirFunc),
     /*  85 */ SyscallDesc("creat", unimplementedFunc),
-    /*  86 */ SyscallDesc("link", unimplementedFunc),
+    /*  86 */ SyscallDesc("link", linkFunc),
     /*  87 */ SyscallDesc("unlink", unlinkFunc),
     /*  88 */ SyscallDesc("symlink", symlinkFunc),
     /*  89 */ SyscallDesc("readlink", readlinkFunc),
diff --git a/src/sim/syscall_emul.cc b/src/sim/syscall_emul.cc
index 7718646..91f00ca 100644
--- a/src/sim/syscall_emul.cc
+++ b/src/sim/syscall_emul.cc
@@ -483,6 +483,28 @@
 }
 
 SyscallReturn
+linkFunc(SyscallDesc *desc, int num, ThreadContext *tc)
+{
+    string path;
+    string new_path;
+
+    int index = 0;
+    auto p = tc->getProcessPtr();
+    auto mem_state = p->getMemState();
+    auto &virt_mem = mem_state->getVirtMem();
+    if (!virt_mem.tryReadString(path, p->getSyscallArg(tc, index)))
+        return -EFAULT;
+    if (!virt_mem.tryReadString(new_path, p->getSyscallArg(tc, index)))
+        return -EFAULT;
+
+    path = p->checkPathRedirect(path);
+    new_path = p->checkPathRedirect(new_path);
+
+    int result = link(path.c_str(), new_path.c_str());
+    return (result == -1) ? -errno : result;
+}
+
+SyscallReturn
 symlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc)
 {
     string path;
diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
index 72c6b7f..19469d1 100644
--- a/src/sim/syscall_emul.hh
+++ b/src/sim/syscall_emul.hh
@@ -195,6 +195,9 @@
                            int index);
 SyscallReturn unlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc);
 
+/// Target link() handler
+SyscallReturn linkFunc(SyscallDesc *desc, int num, ThreadContext *tc);
+
 /// Target symlink() handler.
 SyscallReturn symlinkFunc(SyscallDesc *desc, int num, ThreadContext *tc);