Subject: [PATCH v4 00/27] ata: optimize core code size on PATA only setups

Hi,

There have been reports in the past of libata core code size
being a problem in migration from deprecated IDE subsystem on
legacy PATA only systems, i.e.:

https://lore.kernel.org/linux-ide/[email protected]/

This patchset re-organizes libata core code to exclude SATA
specific code from being built for PATA only setups.

The end result is up to 24% (by 23949 bytes, from 101769 bytes to
77820 bytes) smaller libata core code size (as measured for m68k
arch using modified atari_defconfig) on affected setups.

I've tested this patchset using pata_falcon driver under ARAnyM
emulator.


patches #1-11 are general fixes/cleanups done in the process of
making the patchset (there should be no inter-dependencies between
them except patch #10 which depends on patch #9)

patch #12 separates PATA timings code to libata-pata-timings.c file

patches #13-15 let compiler optimize out SATA specific code on
non-SATA hosts by adding !IS_ENABLED(CONFIG_SATA_HOST) instances

patches #16-22 separate SATA only code from libata-core.c file to
libata-sata.c one

patches #23-24 separate SATA only code from libata-scsi.c file to
libata-sata.c one

patches #25-26 separate SATA only code from libata-eh.c file to
libata-sata.c one

patch #27 makes "libata.force" kernel parameter optional


Changes since v3
(https://lore.kernel.org/linux-ide/[email protected]/):
- rebased on top of next-20200317
- fixed sdev_attrs initializer entry defined twice issue found by
kbuild-test-robot/sparse in "ata: expose ncq_enable_prio sysfs
attribute only on NCQ capable hosts" patch

Changes since v2
(https://lore.kernel.org/linux-ide/[email protected]/):
- rebased on top of next-20200227
- added "ata: optimize ata_scsi_rbuf[] size" patch

Changes since v1
(https://lore.kernel.org/linux-ide/[email protected]/):
- added Acked-by: tag from Tejun to "ata: remove stale maintainership
information from core code" patch
- added Reviewed-by: tag from Martin to "ata: make SATA_PMP option
selectable only if any SATA host driver is enabled" patch
- added Reviewed-by: tag from Christoph to following patches:
- "ata: simplify ata_scsiop_inq_89()"
- "ata: use COMMAND_LINE_SIZE for ata_force_param_buf[] size"
- "ata: optimize struct ata_force_param size"
- "ata: move EXPORT_SYMBOL_GPL()s close to exported code"
- "ata: remove EXPORT_SYMBOL_GPL()s not used by modules"
- converted "ata: add CONFIG_SATA_HOST=n version of ata_ncq_enabled()"
patch to use IS_ENABLED()
- added "ata: let compiler optimize out ata_dev_config_ncq() on
non-SATA hosts" and "ata: let compiler optimize out ata_eh_set_lpm()
on non-SATA hosts" patches
- moved "ata: move sata_scr_*() to libata-core-sata.c" patch just
after "ata: start separating SATA specific code from libata-core.c"
one
- dropped no longer needed patches (code savings <= 8 bytes):
- "ata: move ata_do_link_spd_horkage() to libata-core-sata.c"
- "ata: move ata_dev_config_ncq*() to libata-core-sata.c"
- "ata: move sata_print_link_status() to libata-core-sata.c"
- "ata: move sata_down_spd_limit() to libata-core-sata.c"
- "ata: move sata_link_init_spd() to libata-core-sata.c"
- "ata: move ata_eh_set_lpm() to libata-core-sata.c"
- removed superfluos ifdefs
- dropped file names in top of file headers
- merged libata-scsi-sata.c and libata-eh-sata.c into libata-sata.c
- emphasised in patch descriptions that atari_defconfig used for
measurements has been modified (original one is still using
deprecated IDE subsystem)
- added "ata: make "libata.force" kernel parameter optional" patch

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics


Bartlomiej Zolnierkiewicz (27):
ata: remove stale maintainership information from core code
ata: expose ncq_enable_prio sysfs attribute only on NCQ capable hosts
ata: make SATA_PMP option selectable only if any SATA host driver is
enabled
sata_promise: use ata_cable_sata()
ata: simplify ata_scsiop_inq_89()
ata: use COMMAND_LINE_SIZE for ata_force_param_buf[] size
ata: optimize struct ata_force_param size
ata: optimize ata_scsi_rbuf[] size
ata: move EXPORT_SYMBOL_GPL()s close to exported code
ata: remove EXPORT_SYMBOL_GPL()s not used by modules
ata: fix CodingStyle issues in PATA timings code
ata: separate PATA timings code from libata-core.c
ata: add CONFIG_SATA_HOST=n version of ata_ncq_enabled()
ata: let compiler optimize out ata_dev_config_ncq() on non-SATA hosts
ata: let compiler optimize out ata_eh_set_lpm() on non-SATA hosts
ata: start separating SATA specific code from libata-core.c
ata: move sata_scr_*() to libata-sata.c
ata: move *sata_set_spd*() to libata-sata.c
ata: move sata_link_{debounce,resume}() to libata-sata.c
ata: move sata_link_hardreset() to libata-sata.c
ata: move ata_qc_complete_multiple() to libata-sata.c
ata: move sata_deb_timing_*() to libata-sata.c
ata: start separating SATA specific code from libata-scsi.c
ata: move ata_sas_*() to libata-sata.c
ata: start separating SATA specific code from libata-eh.c
ata: move ata_eh_analyze_ncq_error() & co. to libata-sata.c
ata: make "libata.force" kernel parameter optional

drivers/ata/Kconfig | 77 ++
drivers/ata/Makefile | 2 +
drivers/ata/libata-core.c | 1229 +++---------------------
drivers/ata/libata-eh.c | 224 +----
drivers/ata/libata-pata-timings.c | 192 ++++
drivers/ata/libata-sata.c | 1480 +++++++++++++++++++++++++++++
drivers/ata/libata-scsi.c | 544 +----------
drivers/ata/libata-sff.c | 4 -
drivers/ata/libata.h | 25 +-
drivers/ata/sata_promise.c | 8 +-
drivers/scsi/Kconfig | 1 +
drivers/scsi/libsas/Kconfig | 1 +
include/linux/libata.h | 174 ++--
13 files changed, 2066 insertions(+), 1895 deletions(-)
create mode 100644 drivers/ata/libata-pata-timings.c
create mode 100644 drivers/ata/libata-sata.c

--
2.24.1


Subject: [PATCH v4 01/27] ata: remove stale maintainership information from core code

In commit 7634ccd2da97 ("libata: maintainership update") from 2018
Jens has officially taken over libata maintainership from Tejun so
remove stale information from core libata code.

Acked-by: Tejun Heo <[email protected]>
Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
---
drivers/ata/libata-core.c | 4 ----
drivers/ata/libata-eh.c | 4 ----
drivers/ata/libata-scsi.c | 4 ----
drivers/ata/libata-sff.c | 4 ----
4 files changed, 16 deletions(-)

diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 175b2a9dc000..1b509ccc67f3 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -2,10 +2,6 @@
/*
* libata-core.c - helper library for ATA
*
- * Maintained by: Tejun Heo <[email protected]>
- * Please ALWAYS copy [email protected]
- * on emails.
- *
* Copyright 2003-2004 Red Hat, Inc. All rights reserved.
* Copyright 2003-2004 Jeff Garzik
*
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 388f8ed46eab..a14e26aa1391 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -2,10 +2,6 @@
/*
* libata-eh.c - libata error handling
*
- * Maintained by: Tejun Heo <[email protected]>
- * Please ALWAYS copy [email protected]
- * on emails.
- *
* Copyright 2006 Tejun Heo <[email protected]>
*
* libata documentation is available via 'make {ps|pdf}docs',
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index f76ceb520f5e..5a4f43c85131 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -2,10 +2,6 @@
/*
* libata-scsi.c - helper library for ATA
*
- * Maintained by: Tejun Heo <[email protected]>
- * Please ALWAYS copy [email protected]
- * on emails.
- *
* Copyright 2003-2004 Red Hat, Inc. All rights reserved.
* Copyright 2003-2004 Jeff Garzik
*
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index ffe633f13f55..dad59ce95c7d 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -2,10 +2,6 @@
/*
* libata-sff.c - helper library for PCI IDE BMDMA
*
- * Maintained by: Tejun Heo <[email protected]>
- * Please ALWAYS copy [email protected]
- * on emails.
- *
* Copyright 2003-2006 Red Hat, Inc. All rights reserved.
* Copyright 2003-2006 Jeff Garzik
*
--
2.24.1

Subject: [PATCH v4 13/27] ata: add CONFIG_SATA_HOST=n version of ata_ncq_enabled()

When CONFIG_SATA_HOST=n there are no NCQ capable host drivers
built so it is safe to hardwire ata_ncq_enabled() to always
return zero.

Code size savings on m68k arch using (modified) atari_defconfig:

text data bss dec hex filename
before:
37820 572 40 38432 9620 drivers/ata/libata-core.o
21040 105 576 21721 54d9 drivers/ata/libata-scsi.o
17405 18 0 17423 440f drivers/ata/libata-eh.o
after:
37582 572 40 38194 9532 drivers/ata/libata-core.o
20702 105 576 21383 5387 drivers/ata/libata-scsi.o
17353 18 0 17371 43db drivers/ata/libata-eh.o

Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
---
include/linux/libata.h | 2 ++
1 file changed, 2 insertions(+)

diff --git a/include/linux/libata.h b/include/linux/libata.h
index 9ad072b6d007..b1b3e5e0a301 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -1623,6 +1623,8 @@ extern struct ata_device *ata_dev_next(struct ata_device *dev,
*/
static inline int ata_ncq_enabled(struct ata_device *dev)
{
+ if (!IS_ENABLED(CONFIG_SATA_HOST))
+ return 0;
return (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ_OFF |
ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ;
}
--
2.24.1

Subject: [PATCH v4 11/27] ata: fix CodingStyle issues in PATA timings code

* fix the overly long line in ata_timing_quantize()

* use standard kernel CodingStyle in ata_timing_merge()

* do not use assignment in if condition in ata_timing_compute()

* fix non-standard comment style in ata_timing_compute()

Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
---
drivers/ata/libata-core.c | 42 +++++++++++++++++++++++++--------------
1 file changed, 27 insertions(+), 15 deletions(-)

diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index e4df091fdcde..52d32c88b854 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -3263,7 +3263,8 @@ static const struct ata_timing ata_timing[] = {
#define ENOUGH(v, unit) (((v)-1)/(unit)+1)
#define EZ(v, unit) ((v)?ENOUGH(((v) * 1000), unit):0)

-static void ata_timing_quantize(const struct ata_timing *t, struct ata_timing *q, int T, int UT)
+static void ata_timing_quantize(const struct ata_timing *t,
+ struct ata_timing *q, int T, int UT)
{
q->setup = EZ(t->setup, T);
q->act8b = EZ(t->act8b, T);
@@ -3279,15 +3280,24 @@ static void ata_timing_quantize(const struct ata_timing *t, struct ata_timing *q
void ata_timing_merge(const struct ata_timing *a, const struct ata_timing *b,
struct ata_timing *m, unsigned int what)
{
- if (what & ATA_TIMING_SETUP ) m->setup = max(a->setup, b->setup);
- if (what & ATA_TIMING_ACT8B ) m->act8b = max(a->act8b, b->act8b);
- if (what & ATA_TIMING_REC8B ) m->rec8b = max(a->rec8b, b->rec8b);
- if (what & ATA_TIMING_CYC8B ) m->cyc8b = max(a->cyc8b, b->cyc8b);
- if (what & ATA_TIMING_ACTIVE ) m->active = max(a->active, b->active);
- if (what & ATA_TIMING_RECOVER) m->recover = max(a->recover, b->recover);
- if (what & ATA_TIMING_DMACK_HOLD) m->dmack_hold = max(a->dmack_hold, b->dmack_hold);
- if (what & ATA_TIMING_CYCLE ) m->cycle = max(a->cycle, b->cycle);
- if (what & ATA_TIMING_UDMA ) m->udma = max(a->udma, b->udma);
+ if (what & ATA_TIMING_SETUP)
+ m->setup = max(a->setup, b->setup);
+ if (what & ATA_TIMING_ACT8B)
+ m->act8b = max(a->act8b, b->act8b);
+ if (what & ATA_TIMING_REC8B)
+ m->rec8b = max(a->rec8b, b->rec8b);
+ if (what & ATA_TIMING_CYC8B)
+ m->cyc8b = max(a->cyc8b, b->cyc8b);
+ if (what & ATA_TIMING_ACTIVE)
+ m->active = max(a->active, b->active);
+ if (what & ATA_TIMING_RECOVER)
+ m->recover = max(a->recover, b->recover);
+ if (what & ATA_TIMING_DMACK_HOLD)
+ m->dmack_hold = max(a->dmack_hold, b->dmack_hold);
+ if (what & ATA_TIMING_CYCLE)
+ m->cycle = max(a->cycle, b->cycle);
+ if (what & ATA_TIMING_UDMA)
+ m->udma = max(a->udma, b->udma);
}
EXPORT_SYMBOL_GPL(ata_timing_merge);

@@ -3318,8 +3328,8 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
/*
* Find the mode.
*/
-
- if (!(s = ata_timing_find_mode(speed)))
+ s = ata_timing_find_mode(speed);
+ if (!s)
return -EINVAL;

memcpy(t, s, sizeof(*s));
@@ -3375,9 +3385,11 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
t->recover = t->cycle - t->active;
}

- /* In a few cases quantisation may produce enough errors to
- leave t->cycle too low for the sum of active and recovery
- if so we must correct this */
+ /*
+ * In a few cases quantisation may produce enough errors to
+ * leave t->cycle too low for the sum of active and recovery
+ * if so we must correct this.
+ */
if (t->active + t->recover > t->cycle)
t->cycle = t->active + t->recover;

--
2.24.1

Subject: [PATCH v4 07/27] ata: optimize struct ata_force_param size

Optimize struct ata_force_param size by:
- using u8 for cbl and spd_limit fields
- using u16 for lflags field

Code size savings on m68k arch using (modified) atari_defconfig:

text data bss dec hex filename
before:
41064 573 40 41677 a2cd drivers/ata/libata-core.o
after:
40654 573 40 41267 a133 drivers/ata/libata-core.o

Reviewed-by: Christoph Hellwig <[email protected]>
Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
---
drivers/ata/libata-core.c | 6 +++---
include/linux/libata.h | 1 +
2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 0c9ac46d3109..9660c1af5156 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -90,12 +90,12 @@ atomic_t ata_print_id = ATOMIC_INIT(0);

struct ata_force_param {
const char *name;
- unsigned int cbl;
- int spd_limit;
+ u8 cbl;
+ u8 spd_limit;
unsigned long xfer_mask;
unsigned int horkage_on;
unsigned int horkage_off;
- unsigned int lflags;
+ u16 lflags;
};

struct ata_force_ent {
diff --git a/include/linux/libata.h b/include/linux/libata.h
index fe8a360b4956..c6d94e40ca73 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -163,6 +163,7 @@ enum {
ATA_DEV_NONE = 11, /* no device */

/* struct ata_link flags */
+ /* NOTE: struct ata_force_param currently stores lflags in u16 */
ATA_LFLAG_NO_HRST = (1 << 1), /* avoid hardreset */
ATA_LFLAG_NO_SRST = (1 << 2), /* avoid softreset */
ATA_LFLAG_ASSUME_ATA = (1 << 3), /* assume ATA class */
--
2.24.1

Subject: [PATCH v4 08/27] ata: optimize ata_scsi_rbuf[] size

Currently the maximum required size of the ata_scsi_rbuf[] is
576 bytes in ata_scsiop_inq_89() so modify ATA_SCSI_RBUF_SIZE
define accordingly.

Code size savings on m68k arch using (modified) atari_defconfig:

text data bss dec hex filename
before:
20782 105 4096 24983 6197 drivers/ata/libata-scsi.o
after:
20782 105 576 21463 53d7 drivers/ata/libata-scsi.o

Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
---
drivers/ata/libata-scsi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 2a43eef97b87..7bdda82fe886 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -37,7 +37,7 @@
#include "libata.h"
#include "libata-transport.h"

-#define ATA_SCSI_RBUF_SIZE 4096
+#define ATA_SCSI_RBUF_SIZE 576

static DEFINE_SPINLOCK(ata_scsi_rbuf_lock);
static u8 ata_scsi_rbuf[ATA_SCSI_RBUF_SIZE];
--
2.24.1

2020-03-26 09:50:11

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH v4 11/27] ata: fix CodingStyle issues in PATA timings code

On Tue, Mar 17, 2020 at 03:43:17PM +0100, Bartlomiej Zolnierkiewicz wrote:
> * fix the overly long line in ata_timing_quantize()
>
> * use standard kernel CodingStyle in ata_timing_merge()
>
> * do not use assignment in if condition in ata_timing_compute()
>
> * fix non-standard comment style in ata_timing_compute()
>
> Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>

Looks good,

Reviewed-by: Christoph Hellwig <[email protected]>

2020-03-26 09:50:23

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH v4 08/27] ata: optimize ata_scsi_rbuf[] size

On Tue, Mar 17, 2020 at 03:43:14PM +0100, Bartlomiej Zolnierkiewicz wrote:
> Currently the maximum required size of the ata_scsi_rbuf[] is
> 576 bytes in ata_scsiop_inq_89() so modify ATA_SCSI_RBUF_SIZE
> define accordingly.

Looks good,

Reviewed-by: Christoph Hellwig <[email protected]>

Btw, I wonder if we should switch this to a dynamic allocation, as
a lot of people are more concerned about kernel size footprint vs
dynamic allocations.

2020-03-26 09:50:55

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH v4 13/27] ata: add CONFIG_SATA_HOST=n version of ata_ncq_enabled()

On Tue, Mar 17, 2020 at 03:43:19PM +0100, Bartlomiej Zolnierkiewicz wrote:
> When CONFIG_SATA_HOST=n there are no NCQ capable host drivers
> built so it is safe to hardwire ata_ncq_enabled() to always
> return zero.

Looks good,

Reviewed-by: Christoph Hellwig <[email protected]>

2020-03-26 15:17:32

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH v4 00/27] ata: optimize core code size on PATA only setups

On 3/17/20 8:43 AM, Bartlomiej Zolnierkiewicz wrote:
> Hi,
>
> There have been reports in the past of libata core code size
> being a problem in migration from deprecated IDE subsystem on
> legacy PATA only systems, i.e.:
>
> https://lore.kernel.org/linux-ide/[email protected]/
>
> This patchset re-organizes libata core code to exclude SATA
> specific code from being built for PATA only setups.
>
> The end result is up to 24% (by 23949 bytes, from 101769 bytes to
> 77820 bytes) smaller libata core code size (as measured for m68k
> arch using modified atari_defconfig) on affected setups.
>
> I've tested this patchset using pata_falcon driver under ARAnyM
> emulator.

Bart, I'd like to get this into 5.7, can you rebase on current
for-5.7/libata? As you know, I dropped the dprintk series, and it's
now throwing rejects.

--
Jens Axboe

Subject: Re: [PATCH v4 00/27] ata: optimize core code size on PATA only setups


On 3/26/20 4:16 PM, Jens Axboe wrote:
> On 3/17/20 8:43 AM, Bartlomiej Zolnierkiewicz wrote:
>> Hi,
>>
>> There have been reports in the past of libata core code size
>> being a problem in migration from deprecated IDE subsystem on
>> legacy PATA only systems, i.e.:
>>
>> https://lore.kernel.org/linux-ide/[email protected]/
>>
>> This patchset re-organizes libata core code to exclude SATA
>> specific code from being built for PATA only setups.
>>
>> The end result is up to 24% (by 23949 bytes, from 101769 bytes to
>> 77820 bytes) smaller libata core code size (as measured for m68k
>> arch using modified atari_defconfig) on affected setups.
>>
>> I've tested this patchset using pata_falcon driver under ARAnyM
>> emulator.
>
> Bart, I'd like to get this into 5.7, can you rebase on current
> for-5.7/libata? As you know, I dropped the dprintk series, and it's
> now throwing rejects.

Sure, I've just posted v5 (I've rebased it on today's -next and
added Reviewed-by tags from Christoph).

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics