요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
==============
Firmware cache
==============
When Linux resumes from suspend some device drivers require firmware lookups to
re-initialize devices. During resume there may be a period of time during which
firmware lookups are not possible, during this short period of time firmware
requests will fail. Time is of essence though, and delaying drivers to wait for
the root filesystem for firmware delays user experience with device
functionality. In order to support these requirements the firmware
infrastructure implements a firmware cache for device drivers for most API
calls, automatically behind the scenes.
The firmware cache makes using certain firmware API calls safe during a device
driver's suspend and resume callback. Users of these API calls needn't cache
the firmware by themselves for dealing with firmware loss during system resume.
The firmware cache works by requesting for firmware prior to suspend and
caching it in memory. Upon resume device drivers using the firmware API will
have access to the firmware immediately, without having to wait for the root
filesystem to mount or dealing with possible race issues with lookups as the
root filesystem mounts.
Some implementation details about the firmware cache setup:
* The firmware cache is setup by adding a devres entry for each device that
uses all synchronous call except :c:func:`request_firmware_into_buf`.
* If an asynchronous call is used the firmware cache is only set up for a
device if the second argument (uevent) to request_firmware_nowait() is
true. When uevent is true it requests that a kobject uevent be sent to
userspace for the firmware request through the sysfs fallback mechanism
if the firmware file is not found.
* If the firmware cache is determined to be needed as per the above two
criteria the firmware cache is setup by adding a devres entry for the
device making the firmware request.
* The firmware devres entry is maintained throughout the lifetime of the
device. This means that even if you release_firmware() the firmware cache
will still be used on resume from suspend.
* The timeout for the fallback mechanism is temporarily reduced to 10 seconds
as the firmware cache is set up during suspend, the timeout is set back to
the old value you had configured after the cache is set up.
* Upon suspend any pending non-uevent firmware requests are killed to avoid
stalling the kernel, this is done with kill_requests_without_uevent(). Kernel
calls requiring the non-uevent therefore need to implement their own firmware
cache mechanism but must not use the firmware API on suspend.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
Firmware cache가 필요한 이유
1-12문서 제목은 `Firmware cache`입니다.
Linux가 suspend에서 resume할 때 일부 device driver는 device를 다시 초기화하려고 firmware lookup을 수행해야 합니다. Resume 중에는 잠시 firmware lookup이 불가능할 수 있어 이 짧은 기간에 firmware request가 실패합니다.
하지만 시간은 중요합니다. Firmware를 얻기 위해 root filesystem을 기다리도록 driver를 지연하면 사용자가 device 기능을 다시 쓰기까지의 시간이 늘어납니다.
이 요구를 지원하기 위해 firmware infrastructure는 대부분의 firmware API call 뒤에서 자동으로 동작하는 device driver용 firmware cache를 구현합니다.
Suspend와 resume의 cache 생명주기
13-22Firmware cache 덕분에 특정 firmware API call은 device driver의 suspend·resume callback 안에서도 안전하게 사용할 수 있습니다. 이 API 사용자는 system resume 때 firmware가 사라지는 상황에 대비해 firmware를 직접 cache할 필요가 없습니다.
Firmware cache는 suspend 전에 firmware를 request해 memory에 저장합니다. Resume하면 firmware API를 사용하는 device driver는 root filesystem mount를 기다리거나 mount 중 lookup race를 처리하지 않고 즉시 firmware에 접근할 수 있습니다.
Suspend 전에 firmware를 확보해 resume 시 filesystem 의존성을 제거합니다.
Cache 설정 조건과 devres lifetime
23-41Firmware cache 설정의 구현 세부 사항은 다음과 같습니다.
- `request_firmware_into_buf()`를 제외한 모든 synchronous call을 사용하는 각 device에는 devres entry를 추가해 firmware cache를 설정합니다.
- Asynchronous call을 사용할 때는 `request_firmware_nowait()`의 두 번째 argument인 `uevent`가 true인 경우에만 해당 device의 firmware cache를 설정합니다.
- `uevent`가 true이면 firmware file을 찾지 못했을 때 sysfs fallback mechanism을 통해 firmware request용 kobject uevent를 userspace로 보내도록 요청합니다.
- 위 두 기준으로 cache가 필요하다고 판단되면 firmware request를 수행한 device에 devres entry를 추가합니다.
- Firmware devres entry는 device lifetime 전체에 걸쳐 유지됩니다. 따라서 `release_firmware()`를 호출해도 suspend에서 resume할 때 firmware cache를 계속 사용합니다.
Call 방식과 uevent flag가 automatic cache 생성 여부를 결정합니다.
Suspend 중 timeout과 non-uevent request
42-51Suspend 중 firmware cache를 설정하는 동안 fallback mechanism timeout을 임시로 10초로 줄입니다. Cache 설정이 끝나면 사용자가 구성했던 이전 timeout 값으로 되돌립니다.
Suspend할 때 kernel이 멈추지 않도록 pending 상태인 non-uevent firmware request를 모두 종료합니다. 이 작업은 `kill_requests_without_uevent()`가 수행합니다.
따라서 non-uevent가 필요한 kernel call은 자체 firmware cache mechanism을 구현해야 하며 suspend 중 firmware API를 사용해서는 안 됩니다.
Cache 설정 중 timeout과 pending request 처리 규칙입니다.
요약과 해설
firmware_cache.rst:1-51Firmware cache는 suspend 전에 firmware를 memory에 확보해 resume callback에서 즉시 사용할 수 있게 합니다. Synchronous API 대부분과 `uevent=true`인 asynchronous request가 자동 cache 대상입니다.
Devres entry는 device lifetime 동안 남고, cache 구성 중 fallback timeout은 10초로 줄어듭니다. Non-uevent request는 suspend 때 종료되므로 caller가 자체 cache를 구현해야 합니다.