shim_benchmark.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Copyright (C) 2014 Stony Brook University
  2. This file is part of Graphene Library OS.
  3. Graphene Library OS is free software: you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License
  5. as published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. Graphene Library OS is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /*
  14. * shim_benchmark.c
  15. *
  16. * Implementation of system call "benchmark_ipc", "send_rpc" and "recv_rpc".
  17. * (These system calls are added for benchmarking purpose.)
  18. */
  19. #include <errno.h>
  20. #include <shim_internal.h>
  21. #include <shim_ipc.h>
  22. #include <shim_profile.h>
  23. #include <shim_table.h>
  24. #include <shim_unistd.h>
  25. int get_pid_port(IDTYPE pid, IDTYPE* dest, struct shim_ipc_port** port);
  26. int shim_do_benchmark_rpc(pid_t pid, int times, const void* buf, size_t size) {
  27. INC_PROFILE_OCCURENCE(syscall_use_ipc);
  28. int ret = 0;
  29. IDTYPE dest;
  30. struct shim_ipc_port* port = NULL;
  31. if ((ret = get_pid_port(pid, &dest, &port)) < 0)
  32. return ret;
  33. ret = ipc_pid_nop_send(port, dest, times, buf, size);
  34. put_ipc_port(port);
  35. return ret;
  36. }
  37. size_t shim_do_send_rpc(pid_t pid, const void* buf, size_t size) {
  38. return ipc_pid_sendrpc_send(pid, get_cur_tid(), buf, size);
  39. }
  40. int get_rpc_msg(IDTYPE* sender, void* buf, int len);
  41. size_t shim_do_recv_rpc(pid_t* pid, void* buf, size_t size) {
  42. IDTYPE sender;
  43. int ret = get_rpc_msg(&sender, buf, size);
  44. if (ret < 0)
  45. return ret;
  46. if (pid)
  47. *pid = sender;
  48. return ret;
  49. }