From d306532c5d9a29c2dbed50a29fc649a92a0a31c6 Mon Sep 17 00:00:00 2001 From: Marcin Copik Date: Mon, 22 Jul 2024 22:35:38 +0200 Subject: [PATCH 1/6] [local] Add new Dockerfile with proper build of PAPI --- dockerfiles/local/python/Dockerfile.run | 1 - dockerfiles/local/python/Dockerfile.run-papi | 37 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 dockerfiles/local/python/Dockerfile.run-papi diff --git a/dockerfiles/local/python/Dockerfile.run b/dockerfiles/local/python/Dockerfile.run index 76847260..07064866 100755 --- a/dockerfiles/local/python/Dockerfile.run +++ b/dockerfiles/local/python/Dockerfile.run @@ -15,7 +15,6 @@ COPY dockerfiles/local/python/*.py /sebs/ COPY dockerfiles/local/python/run_server.sh /sebs/ COPY dockerfiles/local/python/timeit.sh /sebs/ COPY dockerfiles/local/python/runners.json /sebs/ -ADD third-party/pypapi/pypapi /sebs/pypapi ENV PYTHONPATH=/sebs/.python_packages/lib/site-packages:$PYTHONPATH COPY dockerfiles/local/entrypoint.sh /sebs/entrypoint.sh diff --git a/dockerfiles/local/python/Dockerfile.run-papi b/dockerfiles/local/python/Dockerfile.run-papi new file mode 100755 index 00000000..149407d8 --- /dev/null +++ b/dockerfiles/local/python/Dockerfile.run-papi @@ -0,0 +1,37 @@ +ARG BASE_IMAGE +FROM ${BASE_IMAGE} + +RUN deps=''\ + && apt-get update\ + # for route and sudo + && apt-get install --no-install-recommends -y make gcc libc6-dev\ + && pip3 install cffi + +ADD third-party/pypapi /pypapi +RUN cd /pypapi && python setup.py build && python pypapi/papi_build.py + +FROM ${BASE_IMAGE} + +COPY --from=0 /pypapi/ /pypapi/ + +RUN deps=''\ + && apt-get update\ + # for route and sudo + && apt-get install --no-install-recommends -y curl gosu net-tools sudo ${deps}\ + && apt-get purge -y --auto-remove ${deps}\ + && pip3 install cffi minio bottle + +RUN mkdir -p /sebs +COPY dockerfiles/local/run.sh /sebs/ +COPY dockerfiles/local/*.py /sebs/ +COPY dockerfiles/local/python/*.py /sebs/ +COPY dockerfiles/local/python/run_server.sh /sebs/ +COPY dockerfiles/local/python/timeit.sh /sebs/ +COPY dockerfiles/local/python/runners.json /sebs/ +ENV PYTHONPATH=/pypapi:/sebs/.python_packages/lib/site-packages:$PYTHONPATH + +COPY dockerfiles/local/entrypoint.sh /sebs/entrypoint.sh +RUN chmod +x /sebs/entrypoint.sh +RUN chmod +x /sebs/run.sh + +ENTRYPOINT ["/sebs/entrypoint.sh"] From f36d609e895abeb5e1e7f1e76858cff0ef50c6e7 Mon Sep 17 00:00:00 2001 From: Marcin Copik Date: Mon, 22 Jul 2024 22:36:06 +0200 Subject: [PATCH 2/6] [local] Remove unnecessary chmod in images --- dockerfiles/local/entrypoint.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/dockerfiles/local/entrypoint.sh b/dockerfiles/local/entrypoint.sh index 5451f551..3c7cdda6 100755 --- a/dockerfiles/local/entrypoint.sh +++ b/dockerfiles/local/entrypoint.sh @@ -13,9 +13,7 @@ if [ ! -z "$CMD" ]; then gosu ${USER} $CMD fi -chown -R ${USER}:${USER} /sebs/ echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/dont-prompt-$USER-for-password usermod -aG sudo ${USER} exec gosu ${USER} "$@" - From 14120ce2819e541d5bb36af1ed262ff13b2f5be4 Mon Sep 17 00:00:00 2001 From: Marcin Copik Date: Mon, 22 Jul 2024 22:37:18 +0200 Subject: [PATCH 3/6] [local] Add CLI option to start containers with PAPI --- sebs.py | 8 +++++++- sebs/local/local.py | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/sebs.py b/sebs.py index ff7f7769..b4744e12 100755 --- a/sebs.py +++ b/sebs.py @@ -408,6 +408,11 @@ def local(): @click.argument("benchmark-input-size", type=click.Choice(["test", "small", "large"])) @click.argument("output", type=str) @click.option("--deployments", default=1, type=int, help="Number of deployed containers.") +@click.option( + "--with-papi/--no-with-papi", + default=True, + help="Start container enabled with PAPI counters.", +) @click.option("--storage-configuration", type=str, help="JSON configuration of deployed storage.") @click.option("--measure-interval", type=int, default=-1, help="Interval duration between memory measurements in ms.") @@ -417,7 +422,7 @@ def local(): help="Remove containers after stopping.", ) @simplified_common_params -def start(benchmark, benchmark_input_size, output, deployments, storage_configuration, +def start(benchmark, benchmark_input_size, output, deployments, with_papi, storage_configuration, measure_interval, remove_containers, **kwargs): """ Start a given number of function instances and a storage instance. @@ -429,6 +434,7 @@ def start(benchmark, benchmark_input_size, output, deployments, storage_configur ) deployment_client = cast(sebs.local.Local, deployment_client) deployment_client.remove_containers = remove_containers + deployment_client.with_papi = with_papi result = sebs.local.Deployment() result.measurement_file = deployment_client.start_measurements(measure_interval) diff --git a/sebs/local/local.py b/sebs/local/local.py index 5a4eb18f..5f1ab054 100644 --- a/sebs/local/local.py +++ b/sebs/local/local.py @@ -47,6 +47,14 @@ def remove_containers(self) -> bool: def remove_containers(self, val: bool): self._remove_containers = val + @property + def with_papi(self) -> bool: + return self._with_papi + + @remove_containers.setter + def with_papi(self, val: bool): + self._with_papi = val + @property def measure_interval(self) -> int: return self._measure_interval @@ -71,6 +79,7 @@ def __init__( self.logging_handlers = logger_handlers self._config = config self._remove_containers = True + self._with_papi = False self._memory_measurement_path: Optional[str] = None # disable external measurements self._measure_interval = -1 @@ -157,8 +166,9 @@ def package_code( def create_function(self, code_package: Benchmark, func_name: str) -> "LocalFunction": - container_name = "{}:run.local.{}.{}".format( + container_name = "{}:{}.local.{}.{}".format( self._system_config.docker_repository(), + "run-papi" if self._with_papi else "run", code_package.language_name, code_package.language_version, ) From 886cfcce17fa28f5521ab72359c939b6df33e062 Mon Sep 17 00:00:00 2001 From: Marcin Copik Date: Mon, 22 Jul 2024 22:37:40 +0200 Subject: [PATCH 4/6] [local] Add build option for special image with PAPI --- config/systems.json | 3 ++- tools/build_docker_images.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/config/systems.json b/config/systems.json index bf095d3f..d9e97d0c 100644 --- a/config/systems.json +++ b/config/systems.json @@ -25,7 +25,8 @@ }, "images": [ "run", - "build" + "build", + "run-papi" ], "username": "docker_user", "deployment": { diff --git a/tools/build_docker_images.py b/tools/build_docker_images.py index 5a5ed046..675a323f 100755 --- a/tools/build_docker_images.py +++ b/tools/build_docker_images.py @@ -12,7 +12,7 @@ parser.add_argument( "--deployment", default=None, choices=["local", "aws", "azure", "gcp"], action="store" ) -parser.add_argument("--type", default=None, choices=["build", "run", "manage"], action="store") +parser.add_argument("--type", default=None, choices=["build", "run", "run-papi", "manage"], action="store") parser.add_argument("--language", default=None, choices=["python", "nodejs"], action="store") parser.add_argument("--language-version", default=None, type=str, action="store") args = parser.parse_args() From 20af4891a33f480b010c97cb79e5c88ce2bd6760 Mon Sep 17 00:00:00 2001 From: Marcin Copik Date: Mon, 22 Jul 2024 22:49:00 +0200 Subject: [PATCH 5/6] [local] Use only a subset of container capabilities to enable HW counters --- sebs/local/local.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sebs/local/local.py b/sebs/local/local.py index 5f1ab054..d60a4b7a 100644 --- a/sebs/local/local.py +++ b/sebs/local/local.py @@ -184,6 +184,12 @@ def create_function(self, code_package: Benchmark, func_name: str) -> "LocalFunc self.name(), code_package.language_name ), } + + options = {} + # Enable PAPI counters + if self.with_papi: + options["cap_add"] = ["PERFMON"] + container = self._docker_client.containers.run( image=container_name, command=f"/bin/bash /sebs/run_server.sh {self.DEFAULT_PORT}", @@ -192,18 +198,13 @@ def create_function(self, code_package: Benchmark, func_name: str) -> "LocalFunc # FIXME: make CPUs configurable # FIXME: configure memory # FIXME: configure timeout - # cpuset_cpus=cpuset, - # required to access perf counters - # alternative: use custom seccomp profile - privileged=True, - security_opt=["seccomp:unconfined"], network_mode="bridge", # somehow removal of containers prevents checkpointing from working? remove=self.remove_containers, stdout=True, stderr=True, detach=True, - # tty=True, + **options ) pid: Optional[int] = None From b5b4b6215f4a135bb06c45c82cb3964cd9d904db Mon Sep 17 00:00:00 2001 From: Marcin Copik Date: Mon, 22 Jul 2024 22:52:00 +0200 Subject: [PATCH 6/6] [local] Fix setter method --- sebs/local/local.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sebs/local/local.py b/sebs/local/local.py index d60a4b7a..31dfc7a9 100644 --- a/sebs/local/local.py +++ b/sebs/local/local.py @@ -51,7 +51,7 @@ def remove_containers(self, val: bool): def with_papi(self) -> bool: return self._with_papi - @remove_containers.setter + @with_papi.setter def with_papi(self, val: bool): self._with_papi = val @@ -204,7 +204,7 @@ def create_function(self, code_package: Benchmark, func_name: str) -> "LocalFunc stdout=True, stderr=True, detach=True, - **options + **options, ) pid: Optional[int] = None