Technische Universität Braunschweig
  • Studium & Lehre
    • Vor dem Studium
      • Informationen für Studieninteressierte
      • Studiengänge von A-Z
      • Bewerbung
      • Fit4TU - Self-Assessment
      • Beratungsangebote für Studieninteressierte
      • Warum Braunschweig?
    • Im Studium
      • Erstsemester-Hub
      • Semestertermine
      • Lehrveranstaltungen
      • Studien-ABC
      • Studienorganisation
      • Beratungsnavi
      • Zusatzqualifikationen
      • Finanzierung und Kosten
      • Besondere Studienbedingungen
      • Gesundheit & Wohlbefinden
      • Campusleben
    • Nach dem Studium
      • Exmatrikulation und Vorlegalisation
      • Nach dem Abschluss
      • Alumni*ae
    • Strategien und Qualitätsmanagement
      • Strategiepapiere für Studium und Lehre
      • Studienqualitätsmittel
      • Studiengangsentwicklung
      • Qualitätsmanagement
      • Systemakkreditierung
      • Rechtliche Grundlagen
      • TU Lehrpreis
    • Für Lehrende
      • Informationen für Lehrende
      • Konzepte
      • Lernmanagementsystem Stud.IP
    • Kontakt
      • Studienservice-Center
      • Sag's uns - in Studium und Lehre
      • Zentrale Studienberatung
      • Immatrikulationsamt
      • Abteilung 16 - Studium und Lehre
      • Career Service
      • Projekthaus
  • Forschung
    • Forschungsprofil
      • Forschungsschwerpunkte
      • Exzellenzcluster der TU Braunschweig
      • Forschungsprojekte
      • Forschungszentren
      • Forschungsprofile der Professuren
    • Frühe Karrierephase
      • Förderung in den frühen Phasen der wissenschaftlichen Karriere
      • Promotion
      • Postdocs
      • Nachwuchsgruppenleitung
      • Junior Professur und Tenure-Track
      • Habilitation
      • Service-Angebote für Wissenschaftler*innen
    • Forschungsdaten & Transparenz
      • Transparenz in der Forschung
      • Forschungsdaten
      • Open Access Strategie
      • Digitale Forschungsanzeige
    • Forschungsförderung
      • Netzwerk Forschungsförderung
      • Datenbanken und Stiftungen
    • Kontakt
      • Forschungsservice
      • Graduiertenakademie
  • International
    • Internationale Studierende
      • Warum Braunschweig?
      • Studium mit Abschluss
      • Austauschstudium
      • TU Braunschweig Summer School
      • Geflüchtete
      • International Student Support
    • Wege ins Ausland
      • Studium im Ausland
      • Praktikum im Ausland
      • Lehren und Forschen im Ausland
      • Arbeiten im Ausland
    • Internationale Forschende
      • Welcome Support
      • Promotionsstudium
      • Service für gastgebende Einrichtungen
    • Sprachen und interkulturelle Kompetenzvermittlung
      • Deutsch lernen
      • Fremdsprachen lernen
      • Interkulturelle Kompetenzvermittlung
    • Internationales Profil
      • Internationalisierung
      • Internationale Kooperationen
      • Strategische Partnerschaften
      • Internationale Netzwerke
    • International House
      • Wir über uns
      • Kontakt & Sprechstunden
      • Aktuelles und Termine
      • International Days
      • 5. Studentische Konferenz: Internationalisierung der Hochschulen
      • Newsletter, Podcast & Videos
      • Stellenausschreibungen
  • Die TU Braunschweig
    • Unser Profil
      • Ziele & Werte
      • Ordnungen und Leitlinien
      • Allianzen & Partner
      • Hochschulentwicklung 2030
      • Stiftungsuniversität
      • Internationale Strategie
      • Fakten & Zahlen
      • Unsere Geschichte
    • Karriere
      • Arbeiten an der TU
      • Stellenmarkt
      • Berufsausbildung an der TU
    • Wirtschaft & Unternehmen
      • Unternehmensgründung
      • Freunde & Förderer
    • Öffentlichkeit
      • Veranstaltungskalender
      • Check-in für Schüler*innen
      • Hochschulinformationstag (HIT)
      • Kinder-Uni
      • Das Studierendenhaus
      • Gasthörer*innen & Senior*innenstudium
      • Nutzung der Universitätsbibliothek
    • Presse & Kommunikation
      • Stabsstelle Presse und Kommunikation
      • Medienservice
      • Ansprechpartner*innen
      • Tipps für Wissenschaftler*innen
      • Themen und Stories
    • Kontakt
      • Allgemeiner Kontakt
      • Anreise
      • Für Hinweisgeber
  • Struktur
    • Leitung & Verwaltung
      • Das Präsidium
      • Stabsstellen
      • Verwaltung
      • Organe, Statusgruppen und Kommissionen
    • Fakultäten
      • Carl-Friedrich-Gauß-Fakultät
      • Fakultät für Lebenswissenschaften
      • Fakultät Architektur, Bauingenieurwesen und Umweltwissenschaften
      • Fakultät für Maschinenbau
      • Fakultät für Elektrotechnik, Informationstechnik, Physik
      • Fakultät für Geistes- und Erziehungswissenschaften
    • Institute
      • Institute von A-Z
    • Einrichtungen
      • Universitätsbibliothek
      • Gauß-IT-Zentrum
      • Zentrale Personalentwicklung
      • International House
      • Projekthaus
      • Transferservice
      • Hochschulsportzentrum
      • Einrichtungen von A-Z
    • Studierendenschaft
      • Studierendenparlament
      • Fachschaften
      • Studentische Wahlen
    • Lehrer*innenbildung
      • Lehrer*innenfortbildung
      • Forschung
    • Chancengleichheit
      • Gleichstellung
      • Familie
      • Diversität
    • Kontakt
      • Personensuche
  • Suche
  • Schnellzugriff
    • Personensuche
    • Webmail
    • cloud.TU Braunschweig
    • Messenger
    • Mensa
    • TUconnect (Studierendenportal)
    • Lehrveranstaltungen
    • Im Notfall
    • Stud.IP
    • UB Katalog
    • Status GITZ-Dienste
    • Störungsmeldung GB3
    • IT Dienste
    • Informationsportal (Beschäftigte)
    • Beratungsnavi
    • Linksammlung
    • DE
    • EN
    • IBR YouTube
    • Facebook
    • Instagram
    • YouTube
    • LinkedIn
    • Mastodon
Menü
  • Struktur
  • Fakultäten
  • Carl-Friedrich-Gauß-Fakultät
  • Institute
  • Institut für Betriebssysteme und Rechnerverbund
  • Prof. Dr.-Ing. Christian Dietrich
  • Advent(2)
  • Spin the Advent Wreath as Fast as You can
Logo IBR
IBR Login
  • Institut für Betriebssysteme und Rechnerverbund
    • News
    • Wir über uns
      • Gesamtes Team
      • Anreise
      • Raumplan
      • Projekte
      • Veröffentlichungen
      • Software
      • News Archiv
    • Connected and Mobile Systems
      • Team
      • Lehrveranstaltungen
      • Abschlussarbeiten
      • Projekte
      • Veröffentlichungen
      • Software
      • Datensätze
    • Verlässliche Systemsoftware
      • Übersicht
      • Team
      • Lehre
      • Arbeiten & Jobs
      • Forschung
      • Publikationen
    • Algorithmik
      • Team
      • Lehrveranstaltungen
      • Abschlussarbeiten
      • Projekte
      • Veröffentlichungen
    • Mikroprozessorlabor
    • Studium
      • Sommersemester 2025
      • Wintersemester 2024/2025
      • Abschlussarbeiten
    • Service
      • Bibliothek
      • Mailinglisten
      • Webmail
      • Knowledgebase
      • Wiki
      • Account Management
      • Service-Status
    • Spin-Offs
      • Docoloc
      • bliq (formerly AIPARK)
      • Confidential Technologies
    • Forschungsverbünde
      • IST.hub
  • Task Overview
  • Git repository
  • Mailing list
  • Matrix-Channel

Spin the Advent Wreath as Fast as You can

☃️
Git-Repository: Template Solution Solution-Diff (Solution is posted at 18:00 CET)
Workload: 174 lines of code
Important System-Calls: io_uring_setup(2), io_uring_register(2)
Recommended Reads:
  • Dec. 7: Select a Gift file 110 lines [select(2)]
  • Dec. 10: Pipes Full of Gravy ipc 131 lines [epoll_create(2), epoll_ctl(2), epoll_wait(2), pipe(7), splice(2)]
Illustration for this exercsie

Until this year, the ELF workshop was modeled more after an old-school German Behörde than a modern service-oriented service desk. When one of the ELF workers would require multiple tools to prepare a certain gift, he goes to his ELF supervisor and ask for the first tool. The supervisor then walks into the equipment-storage facility, fetches the requested tool, and delivers it to the worker ELF, who then asks for the second tool. As you might have noticed, this is less than optimal, so it is your job to build a new workflow, where a worker ELF can ask for all tools at once.

io_uring

In our initial discussion of system calls, we said that many syscalls are synchronous: The user thread issues the system call and is blocked until the system call completes. With select() and epoll(), we've already discussed two system calls that help us to break with this synchronous paradigm as we can perform non-blocking I/O: We can use them to detect if new data arrived on some file descriptor (EPOLLOUT) or if the file-descriptor is ready to accept more data (EPOLLIN). However, we still have to come back regularly to read or write data. For example, to avoid blocking when writing to an FD, we have to call write() (with O_NONBLOCK) over and over again until all data is written out, since the kernel accepts only a certain amount of data without blocking.

Wouldn't it be great, if we could just send a bunch of operations to the kernel and the kernel would signal us, at some later point, when the operation has completed. And this is exactly what asynchronous I/O is all about. We separate issue time and completion of an OS operation for the user thread.

Actually, POSIX also specifies an asynchronous I/O interface with aio(7) that Linux also supports. However, aio has several shortcomings like the need to explicitly poll for completed operations with a system call, which led to development of a new asynchronous system-call interface for Linux: io_uring(7) For a detailed discussion of the existing shortcomings and for a detailed introduction to io_uring, I refer you to "Efficient IO with io_uring" by Jens Axboe, the main author of io_uring. In today's article, we will not explain io_uring in detail, but only give a very coarse overview. Others, including Axboe and Shuveb Hussain have written extensive and excellent introductions.

The most important aspect of io_uring is the usage of memory-mapped ring buffers for the communication between user- and kernel space. The user writes its system call requests as submission queue entries (SQE) and the kernel answers with completion queue entries (CQE). Thereby, the user (and with the correct settings also the kernel) can poll those queues for new entries without crossing the privilege boundary but by only looking at the head and tail pointers of the queue.

   int io_uring_setup(u32 entries, struct io_uring_params *p);
   int io_uring_enter(unsigned int fd, unsigned int to_submit,
                      unsigned int min_complete, unsigned int flags, sigset_t *sig);

The two important system calls for io_uring(7) are: io_uring_setup(2), which we use to create a new uring object in the kernel, and io_uring_enter(2), which we use to explicitly submit to_submit SQEs and (optionally) wait for min_complete CQE entries.

For normal uses, you should use liburing, which is a thin abstraction layer that spares you the gory details of setting up an uring instance and managing SQEs. However, for today, we want to use the low-level interface, which is detailed (with examples to copy from) in io_uring(7).

Task

Complete the given example program that uses io_uring to read arbitrary 4096-byte blocks from a given FILE, while keeping SQ_SIZE requests in flight:

usage: ./iouring SQ_SIZE FILE

The idea is to allow you to experiment with different levels of I/O parallelism: modern SSDs can process multiple requests in parallel. So if you only have one request in flight, you cannot saturate your cool SSD completely. On my machine, I see the following difference between 1 in-flight request and 12 in-flight requests:

$ ./iouring 1 test.jpg
init_ring: sq_size=1
SQ: 1 entries (0x7f5653a7c000), ring: 0x7f5653a7d180
CQ: 2 entries ring: 0x7f5653a7b140
in_flight: 1, read_blocks/s: 4.28K, read_bytes: 16.72 MiB/s
in_flight: 1, read_blocks/s: 9.72K, read_bytes: 37.96 MiB/s
in_flight: 1, read_blocks/s: 9.69K, read_bytes: 37.87 MiB/s
in_flight: 1, read_blocks/s: 9.75K, read_bytes: 38.08 MiB/s
in_flight: 1, read_blocks/s: 9.73K, read_bytes: 38.02 MiB/s

$ ./iouring 12 test.jpg 
init_ring: sq_size=12
SQ: 16 entries (0x7f04304db000), ring: 0x7f04304dc340
CQ: 32 entries ring: 0x7f04304da140
in_flight: 12, read_blocks/s: 93.58K, read_bytes: 365.56 MiB/s
in_flight: 12, read_blocks/s: 121.23K, read_bytes: 473.56 MiB/s
in_flight: 12, read_blocks/s: 121.27K, read_bytes: 473.70 MiB/s
in_flight: 12, read_blocks/s: 121.11K, read_bytes: 473.09 MiB/s
in_flight: 12, read_blocks/s: 121.50K, read_bytes: 474.60 MiB/s
in_flight: 12, read_blocks/s: 121.29K, read_bytes: 473.79 MiB/s

With 128 in-flight requests, I could even read more than 1300 MiB/s. Please note, that the kernel rounds up the submission and completion queue sizes to the next power-of-two.

Hints

  • You can inspire yourself by the example in io_uring(7), which contains a complete example for the low-level interface. But still you should try to understand what is going on there.

  • Use the alloc_buffer() function to get a new buffer for the data and pass its pointer as user_data in the SQE, which will come out again as user_data with the CQE.

  • Play around with different in-flight parameters and observe how your machine reacts. Also, the solution contains two printf() statements to track the submission and completion of requests. Uncomment them and try to track individual requests from the output.

  • Really, play around with io_uring and look at the other SQE-types available, io_uring is the future!

Last modified: 2023-12-01 15:52:27.639846, Last author: , Permalink: /p/advent-16-iouring


aktualisiert am 01.12.2023, 15:52 von Prof. Dr.-Ing. Christian Dietrich

Für alle

Stellen der TU Braunschweig
Jobbörse des Career Service
Merchandising
Sponsoring- & Spendenleistungen
Drittmittelgeförderte Forschungsprojekte
Vertrauenspersonen für Hinweisgeber

Für Studierende

Semestertermine
Lehrveranstaltungen
Studiengänge von A-Z
Informationen für Erstsemester
TUCard

Interne Tools

Status GITZ-Dienste
Handbuch für TYPO3 (Intern)
Corporate Design-Toolbox (Intern)
Glossar (DE-EN)
Meine Daten ändern
Hochschulöffentliche Bekanntmachungen

Kontakt

Technische Universität Braunschweig
Universitätsplatz 2
38106 Braunschweig
Postfach: 38092 Braunschweig
Telefon: +49 (0) 531 391-0

Anreise

© Technische Universität Braunschweig
Impressum Datenschutz Barrierefreiheit