Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update disk image source to addhypercall and gem5bridge-driver #69

Open
wants to merge 15 commits into
base: stable
Choose a base branch
from

Conversation

Harshil2107
Copy link
Contributor

No description provided.

@Harshil2107 Harshil2107 requested a review from erin-le February 5, 2025 22:32
@Harshil2107
Copy link
Contributor Author

I have updated source for the NPB disk image to use hypercalls. I tested the NPB disk images on the staging branch for release 24.1.1. I was able to successfully run NPB benchmarks without using sudo in gem5 KVM simulation. All the hypercalls were triggered as expected.

@Harshil2107
Copy link
Contributor Author

TODO: I need to changes the link and the sha256sum for NPB disk image once the base disk image is uploaded to resources.

Comment on lines +3 to +4
ExecStart=
ExecStart=-/sbin/agetty --autologin gem5 --keep-baud 115200,38400,9600 %I $TERM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why two ExecStarts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first Execstart is to make sure that the current value of Exec start is empty before appending our change.

make -j 32 && \
make INSTALL_MOD_PATH=/workspace/output modules_install

RUN git clone https://github.com/gem5/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=release-staging-v24-1-1-0 && \
Copy link
Contributor

@erin-le erin-le Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the minor release staging branch is merged, remember to change this to stable.

chmod +x pahole-version.sh && \
cd .. && \
make defconfig && \
make -j 32 && \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
make -j 32 && \
make -j $(nproc) && \

make -j $(nproc) && \
make INSTALL_MOD_PATH=/workspace/output modules_install

RUN git clone https://github.com/gem5/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=release-staging-v24-1-1-0 && \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the minor release staging branch is merged, remember to change this to stable.

--file "$DOCKERFILE" \
--output "$OUTPUT" .

echo "Build completed for $1: Output directory is $OUTPUT"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, this message is printed even if the build fails. It would be nice if a different message could be printed for a failure, but it's not high priority.

--file "$DOCKERFILE" \
--output "$OUTPUT" .

echo "Build completed for $1: Output directory is $OUTPUT"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, this message is printed even if the build fails. It would be nice if a different message could be printed for a failure, but it's not high priority.

## Disk Image
After building the Dockerfile, you can retrieve the kernel and modules on your host using the `copy_modules_to_host.sh` script.
- **`scripts/`**: Contains scripts that run on the disk image after installation.
- **`disable-network.sh`**: Disables networking by renaming the Netplan configuration file (`.yaml` → `.yaml.bak`) and disabling network services in systemd.
Copy link
Contributor

@erin-le erin-le Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be good to mention the reason for this, i.e. that this cuts down on boot time

- **`extract-x86-kernel.sh`**: Extracts the kernel from the x86 disk image and moves it to `/home/gem5`. Packer then copies the extracted kernel from the disk image to the host.
- **`increase-system-entropy-for-arm-disk.sh`**: Uses `haveged` to increase system entropy for ARM disk images, reducing boot delays caused by low entropy.
- **`install-common-packages.sh`**: Installs necessary packages common to all disk images.
- **`install-gem5-bridge.sh`**: Clones and builds `gem5-bridge`, allowing the disk image to use `m5ops` commands.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could link to tutorial/ further explanation of gem5 bridge and m5ops commands. Could be either https://bootcamp.gem5.org/#02-Using-gem5/03-running-in-gem5 from the gem5 bootcamp or this docs page: https://www.gem5.org/documentation/general_docs/m5ops/.

- **`install-gem5-bridge.sh`**: Clones and builds `gem5-bridge`, allowing the disk image to use `m5ops` commands.
- **`install-user-benchmarks.sh`**: User-editable script for installing custom benchmarks.
- **`install-user-packages.sh`**: User-editable script for installing additional packages beyond those in `install-common-packages.sh`.
- **`update-gem5-init.sh`**: Updates the `init` file with `gem5_init.sh` from the `files` directory.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add a short description of what gem5_init.sh does, but since most users probably won't need to modify either update-gem5-init.sh or gem5_init.sh, it would also be fine to leave it out.

3. **Verify the Output Directory**
After running the script, a directory named **`my-arm-<kernel_version>-kernel`** will be created in the `kernel-and-modules` directory. This directory contains:

- `vmlinux`: The built kernel (**used in gem5 simulations but not copied to the disk**).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `vmlinux`: The built kernel (**used in gem5 simulations but not copied to the disk**).
- `vmlinux`: The built kernel (**used in gem5 simulations but not copied onto the built disk image**).


```bash
dd if=/dev/zero of=flash0.img bs=1M count=64
dd if=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd of=flash0.img conv=notrunc
```

**Note**: The `build-arm.sh` will make this file for you.
**Note:** Running `build-arm.sh` automatically generates this file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This note should probably be moved above the commands to generate the EFI file.

You could also just remove the section on generating the EFI file, since it's been automated.

Comment on lines +94 to 95
The build assumes execution on an **ARM machine**, as it uses KVM for virtualization. If running on a non-ARM host, update `build-arm.sh` by setting `"use_kvm=false"` in the `./packer build` command.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The build assumes execution on an **ARM machine**, as it uses KVM for virtualization. If running on a non-ARM host, update `build-arm.sh` by setting `"use_kvm=false"` in the `./packer build` command.
The build assumes execution on an **ARM machine**, as it uses KVM for virtualization. If running on a non-ARM host, update `build-arm.sh` by setting `"use_kvm=false"` in the `./packer build` command:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also mention that you need to change build-arm.sh to get the linux_amd64 Packer binary instead of the linux_arm64 binary. Maybe you could put linux_arm64 into a variable in build-arm.sh so it's more convenient for end users to modify? You could do the same in build-x86.sh. Something like the folllowing:

PACKER_SYSTEM_VERSION="linux_amd64"    #"linux_arm64"

# This part installs the packer binary on the arm64 machine as we are assuming
# that we are building the disk image on an arm64 machine.
if [ ! -f ./packer ]; then
    wget https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_${PACKER_SYSTEM_VERSION}.zip;
    unzip packer_${PACKER_VERSION}_${PACKER_SYSTEM_VERSION}.zip;
    rm packer_${PACKER_VERSION}_${PACKER_SYSTEM_VERSION}.zip;
fi


The kernel is extracted using packer's file provisioner with `direction=download` which would copy a file from the image to the host machine. The path specifying in the provisioner copies the file `/home/gem5/vmlinux-x86-ubuntu` to the output directory `disk-image`.
**ARM Build Assumption**:
The build assumes execution on an **ARM machine**, as it uses KVM for virtualization. If running on a non-ARM host, update `build-arm.sh` by setting `"use_kvm=false"` in the `./packer build` command.

Copy link
Contributor

@erin-le erin-le Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```bash
./packer build -var "use_kvm=false" -var "ubuntu_version=${ubuntu_version}" ./packer-scripts/arm-ubuntu.pkr.hcl
```

Ignore the extra whitespace in the opening/closing of the bash code block, it's just there so the suggestion block would be formatted more or less properly

sudo systemctl unmask systemd-networkd-wait-online.service
sudo systemctl enable systemd-networkd-wait-online.service
sudo systemctl start systemd-networkd-wait-online.service # If enabling immediately
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify how to run/where you should add these commands? Can the user add them to a script or do they have to boot the disk image in QEMU, etc.


- You can add more packages to the disk image by updating the `post-installation.sh` script.
- To add files from host to the disk image you can add a file provisioner with source as path in host and destination as path in the image.
- Add more packages by updating `post-installation.sh`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Add more packages by updating `post-installation.sh`.
- Add more packages by modifying `scripts/install-user-packages.sh`. Install benchmarks onto the base disk image by modifying `scripts/install-user-benchmarks.sh`.

}
```
```

If you need to increase the size of the image when adding more libraries and files to the image update the size of the partition in the respective `http/*/user-data` file. Also, update the `disk_size` parameter in `post-installation.sh` to be at least one mega byte more than the size you defined in the `user-data` file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update post-installation.sh to the new script that handles this.

}
```
```

If you need to increase the size of the image when adding more libraries and files to the image update the size of the partition in the respective `http/*/user-data` file. Also, update the `disk_size` parameter in `post-installation.sh` to be at least one mega byte more than the size you defined in the `user-data` file.

**NOTE:** You can extend this disk image by modifying the `post-installation.sh` script, but it requires building the image from scratch.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update post-installation.sh to the new script that handles this.

}
```
```

If you need to increase the size of the image when adding more libraries and files to the image update the size of the partition in the respective `http/*/user-data` file. Also, update the `disk_size` parameter in `post-installation.sh` to be at least one mega byte more than the size you defined in the `user-data` file.

**NOTE:** You can extend this disk image by modifying the `post-installation.sh` script, but it requires building the image from scratch.

To take a pre-built image and add new files or packages, take a look at the following [documentation](https://www.gem5.org/documentation/gem5-stdlib/extending-disk-images).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This link appears to be broken

The port for the vnc viewer is shown in the terminal while packer is running.
```sh
PACKER_LOG=INFO ./build.sh
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A short sentence such as

Suggested change
This causes Packer to print additional debug messages.

would be nice to have here. Not absolutely necessary though

sudo mount -o loop,offset=2097152,norecovery x86-ubuntu/x86-ubuntu-image/x86-ubuntu x86-ubuntu/mount
```
- **Monitor Installation**:
- Use a **VNC viewer** to watch installation. The port is displayed in the terminal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The output may appear as follows:
```bash
==> qemu.initialize: Waiting 10s for boot...
==> qemu.initialize: Connecting to VM via VNC (127.0.0.1:5995)
```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants